Purpose of study: make a page display
The key is to use the limit in the SQL statement to limit the number of records displayed to a few. 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 give you the total number of records
Ceil ($num/10)) If a page of 10 records, this is the total number of pages
So I can write this.
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 the 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:
FirstPage
">prevpage
">nextpage
">lastpage
This is a general idea, you can think how to optimize? Speaking here today, let's talk about some of the issues of attention tomorrow.
http://www.bkjia.com/PHPjc/314897.html www.bkjia.com true http://www.bkjia.com/PHPjc/314897.html techarticle Learning Purpose: To make a paging display the key is to use the limit in the SQL statement to limit the display of records from a few to several. We need a variable $page to record the current page, and a total of ...