【发布时间】:2014-09-26 12:01:45
【问题描述】:
我有这样的分页页面链接。页面增长如下:
1 2 3 4 5 6 7 ,8,9,10 并继续。
但我想限制这一点,所以如果页面超过 5 个,它应该只显示 5 个这样的链接:
1 2 3 4 5... 97 98 99 其中 99 是最后一页。
如果你转到下一页,它只会像这样更改第一页:
3 4 5 ... 97 98 99
function pagination($current_page_number, $total_records_found, $query_string = null)
{
$page = 1;
echo "Page: ";
for ($total_pages = ($total_records_found/NUMBER_PER_PAGE); $total_pages > 0; $total_pages--)
{
if ($page != $current_page_number)
echo "<a href=\"?page=$page" . (($query_string) ? "&$query_string" : "") . "\">";
echo "$page ";
require_once('inc/database.php');
define("NUMBER_PER_PAGE", 5); //number of records per page of the search results
$page = ($_GET['page']) ? $_GET['page'] : 1;
$start = ($page-1) * NUMBER_PER_PAGE;
$sql = "SELECT * FROM members WHERE 1=1";
$total_records = mysql_num_rows(mysql_query($sql));
//we limit our query to the number of results we want per page
$sql .= " LIMIT $start, " . NUMBER_PER_PAGE;
// we display our pagination at the top of our search results
pagination($page, $total_records, "id=$id&username=$username&email=$email");
$loop = mysql_query($sql)
or die ('cannot run the query because: ' . mysql_error());
while ($record = mysql_fetch_assoc($loop))
echo "<br/>{$record['id']}) " . stripslashes($record['username']) . " - {$record['email']}";
echo "<center>" . number_format($total_records) . " search results found</center>";
if ($page != $current_page_number)
echo "</a>";
$page++;
【问题讨论】:
-
在这个类似的帖子中查看答案:stackoverflow.com/questions/8361808/…
标签: php pagination limit paging offset