0

我有一个带有简单分页插件的 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{}
4

2 回答 2

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>";
于 2012-11-26T15:10:08.890 回答
0

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

于 2012-11-26T15:11:40.213 回答