0

mysql/php

我可以让分页工作。但是在第二页它只列出了三个结果。其余页面没有显示结果。我在做什么错?

//$result=mysql_query("select count(*) from users WHERE level > 14");

$result=mysql_query("select count(*) from users WHERE level > 14 ORDER BY uid ASC LIMIT 200");
//$result=mysql_query("SELECT *, COUNT(level) FROM users GROUP by level AND NOT COUNT(*) < 15");


$row=mysql_fetch_row($result);
$tr=$row[0];
$rpp=10;  

$pn=1;
echo mysql_result($result, 0);
if(isset($_GET['pn']))
{
  $pn=$_GET['pn'];
}
$tp=($tr/$rpp);

if($tr%$rpp>0)
{
 $tp++;
}
$from=(($pn-1)*$rpp)+1;
$to=($pn)*($rpp);
//$result=mysql_query("select * from users where uid between $from and $to HAVING level > 14 ");

$result=mysql_query("select * from users where (uid between $from and $to) AND level > 14 ORDER BY uid ASC LIMIT 200");
//$result=mysql_query("select * from users WHERE (uid between $from and $to) AND NOT level < 14");
while($row=mysql_fetch_row($result))
4

1 回答 1

0

您确定要基于 uid 而不是使用 LIMIT 创建分页吗?因为如果删除了任何表行并且您的uid列是基于 AUTOINCREMENT 的 - 您将在某些页面上获得不正确的结果数量。

//first page
SELECT * FROM users WHERE level > 14 ORDER BY uid ASC LIMIT 0, {$results_per_page};
//any page including first
SELECT * FROM users WHERE level > 14 ORDER BY uid ASC LIMIT {$page_number_multiplied_by_results_per_page}, {$results_per_page};

请注意,如果您想使用这种方法,页码应该从 0 开始。

于 2013-06-24T22:24:17.407 回答