PHP Paging problem

Source: Internet
Author: User

 Such sub-points: 

$total _record=50; Here 50 gets the total number of records through SQL
$list _num=5; Set the number of pages to display
$temp = ($page-1) * $list _num;
$total _page=ceil ($total _record/$list _num); Total pages
$sql = "SELECT * FROM table limit $temp, $list _num"; The most important to see the limit $temp, $list _num
$temp is starting from 0, the following $list_num is the number of single-page display
Simple point that there are 50 records in the database, the range of $temp is 0-49.

Give you the idea:
First make sure you want to display several page numbers, and then according to the current page to determine the starting and ending page, such as displaying 4 page numbers,
$page = 5; The current page
$page _num=4; Displays the number of page numbers
$page _tmp= $page _num/2;
The starting and ending page numbers are calculated below
if ($page > $page _tmp)
{
$s _page = $page-$page _tmp;
} else{
$s _page = 1;
}

if (($page + $page _tmp) <= $total _page)
{
$e _page = $page + $page _tmp;
} else{
$e _page = $total _page;
}
//The following is the display result:
for ($i = $s _page; $i <= $e _page; $i + +)
{
echo "<a href=\" ". $_server[' Php_self ']."? Page= ". $i." \ ">". $i. " </a> ";
}

Basically determines the start and end pages based on the current page and the total number of pages. Of course, plus the ellipsis, you just have to judge the two ends can be, the front to see whether the current page is the first page, not can add, end, the same is the same.

PHP Paging problem

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.