- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
$objDB = mysql_select_db("Test");
$strSQL = "SELECT * FROM UserAddedRecord WHERE (Name LIKE '%".$getname."%' and State LIKE '%".$getstate."%' and Cell LIKE '%".$getcell."%' and Custgroup LIKE '%".$getgroup."%') AND user_id=$id";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 5;
if (!isset($_GET['Page'])) {
$Page = 1;
} else {
$Page = $_GET['Page'];
}
$Prev_Page = $Page - 1;
$Next_Page = $Page + 1;
$Page_Start = (($Per_Page * $Page) - $Per_Page);
if ($Num_Rows <= $Per_Page) {
$Num_Pages = 1;
} elseif (($Num_Rows % $Per_Page) == 0) {
$Num_Pages = ($Num_Rows / $Per_Page) ;
} else {
$Num_Pages = ($Num_Rows / $Per_Page) + 1;
$Num_Pages = (int) $Num_Pages;
}
$strSQL .=" order by addedrec_ID DESC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL) or trigger_error(mysql_error());;
if ($Prev_Page) {
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtName=$getname&txtState=$getstate&txtCell=$getcell&txtGroup=$getgroup'><< Back</a> ";
}
for ($i=1; $i <= $Num_Pages; $i++) {
if ($i != $Page) {
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$i&txtName=$getname&txtState=$getstate&txtCell=$getcell&txtGroup=$getgroup'>$i</a> ";
} else {
echo "<b> $i </b>";
}
}
if ($Page!=$Num_Pages) {
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtName=$getname&txtState=$getstate&txtCell=$getcell&txtGroup=$getgroup'>Next>></a> ";
}
mysql_close($objConnect);
这是我用来为数据搜索创建分页页面的代码。但我只是注意到我有太多记录然后它会有太多页码。我试图限制显示的页码,并寻找很多例子..它有很多方法可以做到,但我仍然不知道如何限制我的方法...
最佳答案
好吧,如果你的意思是显示类似的东西
Prev 1 2 3 4 5 6 .. 40 41 Next
Prev 1 2 .. 6 7 8 9 10 .. 40 41 Next
首先我们需要创建一个函数来处理我们需要输出分页的内容。这是我使用的一个功能,效果很好。
function get_paging_info($tot_rows,$pp,$curr_page)
{
$pages = ceil($tot_rows / $pp); // calc pages
$data = array(); // start out array
$data['si'] = ($curr_page * $pp) - $pp; // what row to start at
$data['pages'] = $pages; // add the pages
$data['curr_page'] = $curr_page; // Whats the current page
return $data; //return the paging data
}
现在这个功能非常可靠,对我来说效果很好。
所以你传递了这个函数
好的,现在您有了所需的数据,您需要显示它。
这是我使用的内容,请在您认为“啊,太长了”之前先阅读它。其实很简单。
这是它将返回的快照
<!-- Create the query -->
<?php $count = mysql_fetch_assoc( mysql_query ( "SELECT COUNT( rows ) as count FROM table" ) ) ;
<?php $count = $count[0]['count']; ?>
<!-- Call our function from above -->
<?php $paging_info = get_paging_info($count,5,34); ?>
<p>
<!-- If the current page is more than 1, show the First and Previous links -->
<?php if($paging_info['curr_page'] > 1) : ?>
<a href='' title='Page 1'>First</a>
<a href='' title='Page <?php echo ($paging_info['curr_page'] - 1); ?>'>Prev</a>
<?php endif; ?>
<?php
//setup starting point
//$max is equal to number of links shown
$max = 7;
if($paging_info['curr_page'] < $max)
$sp = 1;
elseif($paging_info['curr_page'] >= ($paging_info['pages'] - floor($max / 2)) )
$sp = $paging_info['pages'] - $max + 1;
elseif($paging_info['curr_page'] >= $max)
$sp = $paging_info['curr_page'] - floor($max/2);
?>
<!-- If the current page >= $max then show link to 1st page -->
<?php if($paging_info['curr_page'] >= $max) : ?>
<a href='' title='Page 1'>1</a>
..
<?php endif; ?>
<!-- Loop though max number of pages shown and show links either side equal to $max / 2 -->
<?php for($i = $sp; $i <= ($sp + $max -1);$i++) : ?>
<?php
if($i > $paging_info['pages'])
continue;
?>
<?php if($paging_info['curr_page'] == $i) : ?>
<span class='bold'><?php echo $i; ?></span>
<?php else : ?>
<a href='' title='Page <?php echo $i; ?>'><?php echo $i; ?></a>
<?php endif; ?>
<?php endfor; ?>
<!-- If the current page is less than say the last page minus $max pages divided by 2-->
<?php if($paging_info['curr_page'] < ($paging_info['pages'] - floor($max / 2))) : ?>
..
<a href='' title='Page <?php echo $paging_info['pages']; ?>'><?php echo $paging_info['pages']; ?></a>
<?php endif; ?>
<!-- Show last two pages if we're not near them -->
<?php if($paging_info['curr_page'] < $paging_info['pages']) : ?>
<a href='<?php echo str_replace('/page'.$paging_info['curr_page'], '', $paging_info['curr_url']) . '/page'.($paging_info['curr_page'] + 1); ?>' title='Page <?php echo ($paging_info['curr_page'] + 1); ?>'>Next</a>
<a href='<?php echo str_replace('/page'.$paging_info['curr_page'], '', $paging_info['curr_url']) . '/page'.$paging_info['pages']; ?>' title='Page <?php echo $paging_info['pages']; ?>'>Last</a>
<?php endif; ?>
</p>
关于php - 限制分页页码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8361808/
我有一个 ServiceBusQueue(SBQ),它获取大量消息负载。我有一个具有 accessRights(manage) 的 ServiceBusTrigger(SBT),它不断轮询来自 SBQ
在下面给出的结果集中,有 2 个唯一用户 (id),并且查询中可能会出现更多此类用户: 这是多连接查询: select id, name, col1Code, col2Code, col2Va
我正在用 Python 2.7.3 编写一个带有 GRequests 的小脚本和 lxml 可以让我从各种网站收集一些收藏卡价格并进行比较。问题是其中一个网站限制了请求的数量,如果我超过它,就会发回
我想知道何时实际使用删除级联或删除限制以及更新级联或更新限制。我对使用它们或在我的数据库中应用感到很困惑。 最佳答案 在外键约束上使用级联运算符是一个热门话题。 理论上,如果您知道删除父对象也将自动删
下面是我的输出,我只想显示那些重复的名字。每个名字都是飞行员,数字是飞行员驾驶的飞机类型。我想显示驾驶不止一架飞机的飞行员的姓名。我正在使用 sql*plus PIL_PILOTNAME
我正在评估不同的移动框架,我认为 nativescript 是一个不错的选择。但我不知道开发过程是否存在限制。例如,我对样式有限制(这并不重要),但我想知道将来我是否可以有限制并且不能使用某些 nat
我正在尝试使用 grails 数据绑定(bind)将一些表单参数映射到我的模型中,但我认为在映射嵌入式集合方面可能存在一些限制。 例如,如果我提交一些这样的参数,那么映射工作正常: //this wo
是否可以将 django 自过滤器起的时间限制为 7 天。如果日期超过 7 天,则不应用过滤器 最佳答案 timesince 的源代码位于 django/django/utils/timesince.
我想在我的网站上嵌入一个 PayPal 捐赠按钮。但问题是我住在伊朗——这个国家受到制裁,人们不使用国际银行账户或主要信用卡。 有什么想法吗?请帮忙! 问候 沮丧 最佳答案 您可以在伊朗境内使用为伊朗
这是我的查询 select PhoneNumber as _data,PhoneType as _type from contact_phonenumbers where ContactID = 3
这个问题在这里已经有了答案: What is the maximum number of parameters passed to $in query in MongoDB? (4 个答案) 关闭
我的一个项目的 AndroidManifest.xml 变得越来越大(> 1000 行),因为我必须对某些文件类型使用react并且涵盖所有情况变得越来越复杂。我想知道 list 大小是否有任何限制。
在使用 Sybase、Infomix、DB2 等其他数据库产品多年后使用 MySQL 5.1 Enterprise 时;我遇到了 MySQL 不会做的事情。例如,它只能为 SELECT 查询生成 EX
这个问题在这里已经有了答案: What is the maximum number of parameters passed to $in query in MongoDB? (4 个回答) 关闭5年
通常我们是在{$apache}/conf/httpd.conf中设置Apache的参数,然而我们并没有发现可以设置日志文件大小的配置指令,通过参考http://httpd.apache.org/do
我正在搜索最大的 Android SharedPreferences 键值对,但找不到任何好的答案。其次,我想问一下,如果我有一个键,它的字符串值限制是多少。多少字符可以放入其中。如果我需要频繁更改值
我目前正在试验 SoundCloud API,并注意到我对/tracks 资源的 GET 请求一次从不返回超过 200 个结果。关于这个的几个问题: 这个限制是故意的吗? 有没有办法增加这个限制? 如
我正在与一家名为 Dwolla 的金融技术公司合作,该公司提供了一个 API,用于将银行信息附加到用户并收取/发送 ACH 付款。 他们需要我将我的 TLS 最低版本升级到 1.2(禁用 TLS 1.
我在 PHP 中有一个多维数组,如下所示: $array = Array ( [0] => Array ( [bill] => 1 ) [1] => Array ( [
我在获取下一个查询的第一行时遇到了问题: Select mar.Title MarketTitle, ololo.NUMBER, ololo.Title from Markets mar JOIN(
我是一名优秀的程序员,十分优秀!