Ten days learning php daily learning objective: to make a page 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:
FirstPage
"> PrevPage
"> NextPage
"> LastPage
This is a general idea. you can think about how to optimize it? Today, let's talk about some important issues tomorrow.