分页不通过总页数值

时间:2012-11-26 14:53:58

标签: php mysql pagination

我有一个带有简单分页AddOn的MySql查询,它只显示下一个和前一个。

我遇到的问题是,当它在下一页滚动时,它只显示更多按钮但没有数据。如果我检查页面总页数的值,它没有值。以下是我的代码。这并不完美,但我只是想自己构建它,所以任何指针都会受到赞赏。

由于

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

2 个答案:

答案 0 :(得分:1)

您将制造商保存到变量$ man:

$man = $_GET['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>";

答案 1 :(得分:0)

Pagination工作正常,我只是注意到next和prev按钮中的制造商变量拼错了,这导致了问题所以上面的代码适用于基本的分页脚本。