简体   繁体   English

分页未通过总页面价值

[英]pagination not passing total pages value

I have a MySql query with a simple pagination AddOn, that shows just a next and previous. 我有一个带有简单分页插件的MySql查询,它仅显示下一个和上一个。

The problem I am having is that when it rolls in the next page it just shows the more button but no data. 我遇到的问题是,当它在下一页滚动时,它仅显示more按钮,但没有数据。 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中:

$man = $_GET['manufacturer'];

but in the link you use (empty) variable $manufacturer 但是在链接中,您使用了(空)变量$ 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>";

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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