- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个分页脚本,它显示所有页面的列表,如下所示:上一个 [1][2][3][4][5][6][7][8][9][10][11][12][13][14] 下一个
但我想一次只显示十个数字:上一个 [3][4][5][6][7][8][9][10][11][12] 下一个
我怎样才能做到这一点?到目前为止,这是我的代码:
<?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;
?>
最佳答案
10 个下页
for($i = $page + 1; $i <= min($page + 11, $total_pages); $i++)
或者如果你想要 5 个上一个和 5 个下一个
for($i = max(1, $page - 5); $i <= min($page + 5, $total_pages); $i++)
关于php - 分页 - 每页 10 页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3036909/
在 HTML5 中,是否可以创建仅供单个网页访问的本地存储? 我目前正在尝试编写独立的单页应用程序的可能性,以及用户是否可以自己托管它们,例如在他们的 Dropbox(它有一些公共(public)文件
我正在考虑在我的网站上转换广告的选项,并认为我会从 Google Adsense 开始 - 但是我不确定每页实际上可以有多少广告。我猜可以将横幅与说广告块等混合和匹配 - 那么您可以在单个页面上拥有的
我使用 Jekyll 创建了我的博客。有人告诉我,我的网站正在为某些页面编制 3 个 URL 的索引,这将被归类为 Google 的重复内容。我注意到我可以访问: https://villaagogo
我正在将 sitemesh 用于基于 spring 的站点。问题是我有一些 javascript,我希望它使用 jquery 在一个特定页面的 onload 事件上运行 $(function() {
我有一个分页脚本,它显示所有页面的列表,如下所示: 上一个 [1][2][3][4][5][6][7][8][9][10][11][12][13][14] 下一个 但我想一次只显示十个数字: 上一个
我在 Asp.Net 网站上工作。目前,我正在为每个页面(加载时)创建(并关闭)一个数据库连接。但我不确定,那是真正的方法。我想知道,如果我在静态类或 WebApplication 的主 Global
我想要的是:给定一个 10 页的 pdf 文件,我想在网络上的表格中显示该 pdf 的每一页。实现这一目标的最佳方法是什么?我想一种方法是将这个 10 页 pdf 文件拆分为 10 个 1 页 pdf
我网站的不同页面有不同的 js 需求(主要是插件),有些需要灯箱,有些不需要,有些需要轮播,有些不需要等等。 关于页面加载速度我应该 选项 1 - 在需要时引用每个 js 文件: 所以一页可能有:
我正在使用 Ionic2 slider ,来自其组件:http://ionicframework.com/docs/v2/api/components/slides/Slides/ .我不知道如何让
我正在尝试从 CsrfGuard.properties 启用 token 标准页面。但部署后,当我尝试访问 URL 时,我收到 500 错误,因为它抛出以下异常。 你能帮我解决这个问题吗?我需要在哪里
我是一名优秀的程序员,十分优秀!