Php paging principle simple paging code summary
-
// Determine the number of entries displayed on each page
- // Count (*) queries the total number of items
- // Calculate the total number of pages ceil ()
- // Judge $ _ GET and assign a value to the current page number
- // Mysql Query limit (current page number-1) * number of entries per page, number of entries per page
- // If the total number of items is not empty, loop mysql_fetch_array ()
- // $ _ SERVER ['php _ SELF ']
- // Previous page? Page = current page-1
- // Next page? Page = current page + 1
- // Edit: bbs.it-home.org
- Include ("conn. php ");
- $ Perpagenum = 3;
- $ Total = mysql_fetch_array (mysql_query ("select count (*) FROM message "));
- $ Total = $ total [0];
- $ Totalpage = ceil ($ Total/$ perpagenum );
-
If (! Isset ($ _ GET ['Page']) |! Intval ($ _ GET ['Page']) | $ _ GET ['Page']> $ Totalpage ){
- $ Page = 1;
- } Else {
- $ Page = $ _ GET ['Page'];
- }
-
$ Start = ($ page-1) * $ perpagenum;
- $ SQL = "SELECT * FROM message ORDER BY id DESC LIMIT $ start, $ perpagenum ";
- $ Result = mysql_query ($ SQL );
- $ Contents = mysql_fetch_array ($ result );
- ?>
- If ($ total ){
- }
- Do {
- $ User = $ contents ['user'];
- $ Contact = $ contents ['Contact '];
- $ Content = $ contents ['content'];
- $ Date = $ contents ['Date'];
-
?>
- // Start with php paging
- While ($ contents = mysql_fetch_array ($ result ));
- $ Per = $ page-1;
- $ Next = $ page + 1;
- Echo" There are a Total of ". $ Total." messages, each page ". $ perpagenum.", Total ". $ page."/". $ Totalpage." pages. ";
- If ($ page! = 1 ){
- Echo "homepage ".
- "Previous page ";
- }
- If ($ page! = $ Totalpage ){
- Echo "next page ";
- Echo "last page ";
- }
- ?>
- }
- ?>
|