php+mysql paging query code (mysql paging example)
Release: 2016-07-25 08:52:19
Original
1319 people have browsed it
-
- /*
- * php paging query code
- *
- */
- $perpagenum = 10;//Define how many items to display on each page
- $total = mysql_fetch_array(mysql_query("select count(* ) from a"));//Query how many pieces of data there are in the database
- $Total = $total[0]; //
- $Totalpage = ceil($Total/$perpagenum);//Round up and round up
- if(!isset($_GET['page'])||!intval($_GET['page'])||$_GET['page']>$Totalpage)//Four possible states of page
- {
- $page=1;
- }
- else
- {
- $page=$_GET['page'];//If the above four conditions are not met, the value of page is $_GET['page']
- }
- $ startnum = ($page-1)*$perpagenum;//Start number of items
- $sql = "select * from a order by id limit $startnum,$perpagenum";//Query the required number of items
- 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 "There are ".$Total." records, and each page has ".$perpagenum." records ,Total ".$Totalpage."Pages";
- if($page != 1)
- {
- echo "Homepageecho " Previous page";
- }
- if( $page != $Totalpage)
- {
- echo " Next page" ;
- echo " Last page";
- }
- }
- elseIf $total is empty, output No message
- {
- echo "No message";
- }
- ?>
Copy code
Recommended reading:
- php and ajax no refresh paging code
- php article paging implementation code
- php limit page turning (pagination) code
- PHP paging class with multiple paging methods
- PHP pagination code for previous page and next page
- PHP paging code for the first ten pages and the next ten pages
- Example of simple php pagination code
- A good php pagination code
- A paging function: Previous page Next page
- A useful php paging class
- php long article pagination code
- A practical php paging class
- Fast php paging class
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31