Learning Purpose: Make a paging display
The key is to use the limit in the SQL statement to qualify the displayed records from several to several. We need a variable $page that records the current page and a total number of records $num
For $page if not we let it = 0, if there is <0 let it also = 0, if more than the total number of pages let him = total number of pages.
$EXECC = "SELECT count (*) from TableName";
$RESULTC =mysql_query ($EXECC);
$RSC =mysql_fetch_array ($RESULTC);
$num = $RSC [0];
This will get the total number of records
Ceil ($num/10) If a page 10 records, this is the total number of pages
So you can write that.
if (Empty ($_get[' page '))
{
$page = 0;
}
Else
{
$page =$_get[' page '];
if ($page <0) $page = 0;
if ($page >=ceil ($num/10)) $page =ceil ($num/10) -1;//because page is starting from 0, so to 1
}
So $exec can write $exec = "SELECT * FROM tablename limit". ($page *10). ", 10";
One page is 10 records.
The last thing we need to do is a couple of connections:
<a href= "xxx. Php?page=0 ">FirstPage</a>
<a href= "xxx. Php?page=<?= ($page-1)?> ">PrevPage</a>
<a href= "xxx. php?page=<?= ($page + 1)?> ">NextPage</a>
<a href= "xxx. Php?page=<?=ceil ($num/10) -1?> ">LastPage</a>
This is a general idea, we can think how to optimize? Today, let's talk about some of the issues of attention tomorrow.