10页我有一个显示像这样所有页面的列表分页脚本:
prev [1][2][3][4][5][6][7][8][9][10][11][12][13][14] next
但我想只有一次显示的数字十:
prev [3][4][5][6][7][8][9][10][11][12] next
分页 - 每
我该如何做到这一点?这是我到目前为止的代码:
<?php
/* Set current, prev and next page */
$page = (!isset($_GET['page']))? 1 : $_GET['page'];
$prev = ($page - 1);
$next = ($page + 1);
/* Max results per page */
$max_results = 2;
/* Calculate the offset */
$from = (($page * $max_results) - $max_results);
/* Query the db for total results.
You need to edit the sql to fit your needs */
$result = mysql_query("select title from topics");
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results/$max_results);
$pagination = '';
/* Create a PREV link if there is one */
if($page > 1)
{
$pagination .= '< a href="?page='.$prev.'">Previous</a> ';
}
/* Loop through the total pages */
for($i = 1; $i <= $total_pages; $i++)
{
if(($page) == $i)
{
$pagination .= $i;
}
else
{
$pagination .= '< a href="index.php?page='.$i.'">'.$i.'</a>';
}
}
/* Print NEXT link if there is one */
if($page < $total_pages)
{
$pagination .= '< a hr_ef="?page='.$next.'"> Next</a>';
}
/* Now we have our pagination links in a variable($pagination) ready to
print to the page. I pu it in a variable because you may want to
show them at the top and bottom of the page */
/* Below is how you query the db for ONLY the results for the current page */
$result=mysql_query("select * from topics LIMIT $from, $max_results ");
while ($i = mysql_fetch_array($result))
{
echo $i['title'].'<br />';
}
echo $pagination;
?>
我们想回答的问题,而不是做你的工作适合你。 – 2010-06-14 11:48:41
你打算如何在显示10条记录后自动移动页面。你需要JS,因为你知道 – Starx 2010-06-14 11:48:43
为什么你的href与“_”之间 – Starx 2010-06-14 11:51:43