Objective: To create a paging display
The key is to use the limit in the SQL statement to limit the number of records displayed from several to several. We need a variable $ page for recording the current page, and the total number of records $ num
For $ page, if it does not exist, let it = 0. If there is <0, let it also = 0. If it exceeds the total number of pages, let it = the total number of pages.
$ Execc = "select count (*) from tablename ";
$ Resultc = mysql_query ($ execc );
$ Rsc = mysql_fetch_array ($ resultc );
$ Num = $ rsc [0];
In this way, the total number of records can be obtained.
Ceil ($ num/10) If a page contains 10 records, this is the total number of pages.
So you can write it like 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 page starts from 0, so-1
}
In this way, $ exec can write $ exec = "select * from tablename limit". ($ page * 10). ", 10 ";
// One page is 10 records
What we need to do at last is several 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. You can think about how to optimize it? Today, let's talk about some important issues tomorrow.