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