简体   繁体   中英

pagination not passing total pages value

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{}

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>";

分页工作正常,我只是注意到下一个和上一个按钮中的制造商变量拼写错误,这引起了问题,因此上面的代码对于基本的分页脚本来说工作正常。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM