Php + mysql paging query code (mysql paging example)
- /*
- * Php paging query code
- *
- */
- $ Perpagenum = 10; // defines the number of entries displayed on each page.
- $ Total = mysql_fetch_array (mysql_query ("select count (*) from a"); // query the total number of data records in the database
- $ Total = $ total [0]; //
- $ Totalpage = ceil ($ Total/$ perpagenum); // go to the house and get the integer
- If (! Isset ($ _ GET ['Page']) |! Intval ($ _ GET ['Page']) | $ _ GET ['Page']> $ Totalpage) // Four possible page states
- {
- $ Page = 1;
- }
- Else
- {
- $ Page = $ _ GET ['Page']; // if the preceding conditions are not met, the page value is $ _ GET ['Page']
- }
- $ Startnum = ($ page-1) * $ perpagenum; // number of start entries
- $ SQL = "select * from a order by id limit $ startnum, $ perpagenum"; // query the number of required entries
- Echo $ SQL ."
- ";
- $ Rs = mysql_query ($ SQL );
- $ Contents = mysql_fetch_array ($ rs );
- If ($ total) if $ total is not empty, execute the following statement:
- {
- Do
- {
- $ Id = $ contents ['id'];
- $ Name = $ contents ['name'];
- ?>
-
-
-
-
-
-
-
-
- }
- While ($ contents = mysql_fetch_array ($ rs); // do... while
- $ Per = $ page-1; // Previous page
- $ Next = $ page + 1; // next page
- Echo" A Total of ". $ Total." records, each page ". $ perpagenum.", Total ". $ Totalpage." page ";
- If ($ page! = 1)
- {
- Echo "homepage ";
- Echo "previous page ";
- }
- If ($ page! = $ Totalpage)
- {
- Echo "next page ";
- Echo "last page
";
- }
- }
- Else outputs No message if $ total is null
- {
- Echo" No message ";
- }
- ?>
Recommended reading:
- Php and ajax without refreshing paging code
- Php article paging implementation code
- Php limit paging code
- Php paging class with multiple paging methods
- Php paging code for the previous and next pages
- Top 10 pages and top 10 pages of php paging code
- Example of simple php paging code
- A good php paging code
- One paging function: next page on the previous page
- A handy php paging class
- Php long article paging code
- A Practical php paging class
- Quick php paging
|