Mysql/php
I can get pagination to work. But on page two it only list three results. And rest of pages no results are shown. What are I doing wrong?
//$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))
Are you sure that you want to create a pagination based on uid instead of using LIMIT? Because in case any of the table rows are deleted and your uid
column is an AUTOINCREMENT based - you will get an incorrect number of results on some page.
//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};
Please note that page numbers should start from 0 if you wan to use this approach.