Implementation of PHP paging

Source: Internet
Author: User

1//Get the current page
2 if (isset ($_get[' page ')) {
3 $page = intval ($_get[' page ');
4}
5 else {
6 $page = 1;
7}
8 $PageSize = 1; Number of records per page
9//Get Total quantity
Ten $sql = "SELECT count (*) from blog";
One $result = mysql_query ($sql);
$row = Mysql_fetch_row ($result);
$amount = $row [0];
14/* Total pages calculated
if ($amount) {
if ($amount < $PageSize) {//If the total quantity is less than the number of records per page $pagesize, then there is only one page.
$PageCount = 1;
18}
if ($amount% $PageSize) {//Total quantity divided by the number of records per page taken from
$PageCount =& amp;nbsp; (int) ($amount/$PageSize) +1;//if available, the number of pages equals the total quantity plus 1 of records per page
21}
else{
$PageCount =& amp;nbsp; $amount/$PageSize;//No, the result is the number of pages
24}
25}
else{
$PageCount = 0;
28}*/
$PageCount = Ceil ($amount/$PageSize);//Total pages = Total quantity divided by number per page if there is a small tree, carry < span style= "color: #008000;" >
if ($Page > $PageCount | $page ==0) {//If the current page is greater than the total number of pages
echo "Can't find this page!" ";
Exit ();
33}
34
35//Page link
$PageOut = ";
PNS if ($page ==1) {//If pages are only one page
$PageOut. = ' first page | previous page ';
39}
else{
$PageOut. = ' <a href= "index.php?page=1" > First page & lt;/a>|<a href= "index.php?page=". ($page-1). ' " > previous page </a>| ';
42}
if ($page = = $PageCount | | $PageCount ==0) {//If the current page equals total number
$PageOut. = ' next page | last ';
45}
else{
$PageOut. = ' <a href= ' index.php?page= '. ($page + 1). ' " > next page </a>|<a href= "index.php?page=". $PageCount. ' " > End </a> ';
48}
49//Get Data
if ($amount) {
Wuyi $sql = "SELECT * from Blog limit". ($page-1) * ($PageSize). ", $PageSize";
=mysql_query $result ($sql);
while ($row =mysql_fetch_array ($result)) {//This segment of code is just an example
The $blogs [] = array (' bid ' = $row [' Bid '], ' title ' and ' = ' $row [' title '];
foreach ($blogs as $blog) {
$title = $blog [' title '];
57}
$output = "<a href=index.php?action=blog_del&bid= $blog [bid]> Delete </a>".
"<a href=index.php?action=blog_edit&bid= $blog [bid]> editor </a>".
"<a href=index.php?action=blog_view&bid= $blog [bid]> view </a>";
("template/default/blog.tpl.php");
Echo $PageOut;
63}
($i =1; $i <= $PageCount; $i + +) {//Digital paging
$Pageshow = ($i! = $page)? " <a href= ' index.php?page= '. $i. "' > $i </a> ":" <b> $i </b> ";
Echo $PageShow;
67}
The echo $amount. ' Records, per page '. $PageSize. ' '. $PageCount. ' Page ';
69}

Implementation of PHP paging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.