PHP paging principle simple paging code summary
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-25 08:52:51
Original
1064 people have browsed it
-
-
//Determine how many items are displayed on each page
- //count(*) Query the total number of items
- //Calculate the total number of pages ceil()
- //Judge $_GET and assign the current page number
- //mysql query limit (current page number-1)*number of items per page, number of items 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'];
?>
- < ;td width="193" height="22">Nickname:
|
Posted in: |
|
- }
- //php paging starts
- while($contents=mysql_fetch_array($result));
- $per = $page-1;
- $next= $page+1;
- echo "Total".$ Total." comments, ".$perpagenum." messages per page, total ".$page."/".$Totalpage." pages. ";
- if($page!=1){
- echo "Homepage".
- "Previous page";
- }
- if($page!=$Totalpage){
- echo "Next page";
- echo "Last page";
- }
- ?>
- }
- ?>
-
Copy code
|
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
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11