0

I have a MySql query with a simple pagination AddOn, that shows just a next and previous.

The problem I am having is that when it rolls in the next page it just shows the more button but no data. If I check to see the value of page total pages it doesn't have a value. Below is my code. This isn't perfect but I am just trying to build it myself and so any pointers would be appreciated.

Thanks

$tableName="data";
$targetpage = "exact.php";
$limit = 5;
$type = $_GET['type'];
$man = $_GET['manufacturer'];
$model_group = $_GET['model_group'];
$year = $_GET['year'];
$query = "SELECT COUNT(*) as num FROM $tableName where engine='$type' AND 
manufacturer='$man' and model_group='$model_group' and '$year' BETWEEN start_year AND 
end_year;";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
  $start = ($page - 1) * $limit;
}else{
  $start = 0;
}
// Get page data
$query1 = "SELECT * from $tableName where engine='$type' AND manufacturer='$man' and model_group='$model_group' and '$year' BETWEEN start_year AND end_year LIMIT $start, $limit";
$result = mysql_query($query1);
// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
if ($page > 1){
  echo "<a href='$targetpage?page=$prev&type=$type&manufacturer=$manufacturer&year=$year'><div class='previous'><img src='images/PrevButton1.fw.png' width='108' height='58' style='border: none;'/></span></a>";
}else{}
if ($page < $lastpage){
  echo "<a href='$targetpage?page=$next&type=$type&manufacturer=$manufacturer&year=$year&model_group=$model_group'><div class='next'><img src='images/MoreButton1.fw.png' width='108' height='58' style='border: none;'/></span></a>";
}else{}
dda
  • 6,030
  • 2
  • 25
  • 34
Sam Williams
  • 175
  • 2
  • 3
  • 12
  • Please, don't use mysql_* functions in new code. They are no longer maintained and the deprecation process has begun on it. Use PDO or MySQLi. See this article: http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-function-in-php [1]: http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-function-in-php – ajtrichards Nov 26 '12 at 15:04

2 Answers2

1

You save manufacturer to variable $man:

$man = $_GET['manufacturer'];

but in the link you use (empty) variable $manufacturer

echo "<a href='$targetpage?page=$prev&type=$type&manufacturer=$manufacturer&year=$year'><div class='previous'><img src='images/PrevButton1.fw.png' width='108' height='58' style='border: none;'/></span></a>";
jcjr
  • 1,503
  • 24
  • 40
0

The Pagination worked fine, i just noticed that the manufacturer variable in the next and prev buttons was spelt wrong and this caused the problem so the code above works fine for a basic pagination script.

Sam Williams
  • 175
  • 2
  • 3
  • 12