下面是我的分页代码来显示分页它可以正常工作,也可以正确显示页面。
但问题是当我单击第 2 页时,它会生成错误。
现在我调试代码...并找到概率...问题是查询没有到达位置条件......
例如——分页生成这样的页面...
1-2-3-4-下一页尾页
当我单击第 2 页或第 3 页或最后一页时,查询会生成类似错误
未定义索引:城市未定义的索引:状态
查询未获取 where 子句。
请告诉如何解决此错误...
<?php
$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$limit = 2;
$startpoint = ($page * $limit) - $limit;
$statement = "news";
mysql_set_charset('utf8');
$cit = $_GET['city'];
$sta = $_GET['state'];
$sql="select id,story,headline,photo from {$statement} where state_id = '$sta' and city_id = '$cit' order by id desc LIMIT {$startpoint} , {$limit}";
$query=mysql_query($sql);
?>
<?php echo $Admin->pagination($statement,$limit,$page); ?>
除了页面之外,还需要在查询字符串中传递城市和州值,以使查询正常工作。
因此
http://localhost/nopagination/?page=-1&city=MyCity+OR+1&state=MyState
示例,不要忘记仔细检查所有传入的值。
你必须用分页网址传递城市和州变量,
所以 无论您单击第 2 页或第 3 页,它都会得到这个 2 变量,即 在 where 条件下使用。前任。
<a href="yourpage.php?page=2&city=cityname&state=statename">2</a>
<a href="yourpage.php?page=3&city=cityname&state=statename">3</a>
<a href="yourpage.php?page=4&city=cityname&state=statename">4</a>