PHP分页显示查询结果的问题 写了一个带有查询功能的分页显示PHP网页,当全部数据查询出来后可以正常分页显示,但是只有我通过条件查询,输出的结果大于1页时,也可以正常显示查询出的结果有多少页,页码也可以正常显示,奇怪的是第一页是正常显示,只要点击下页时,显示出来的结果却是全部数据分页显示时的第二页,请问是什么原因,代码如下: 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?php$PageSize = 10;$StartRow = 0; if(empty($_GET['PageNo'])){ if($StartRow == 0){ $PageNo = $StartRow + 1; }}else{ $PageNo = $_GET['PageNo']; $StartRow = ($PageNo - 1) * $PageSize;}if($PageNo % $PageSize == 0){ $CounterStart = $PageNo - ($PageSize - 1);}else{ $CounterStart = $PageNo - ($PageNo % $PageSize) + 1;}$CounterEnd = $CounterStart + ($PageSize - 1);$key1=$HTTP_GET_VARS["key"];$sele1=$_GET['sele'];$match1=$_GET['match'];?><html><head><title>用户信息查询</title><link rel="stylesheet" href="style.css" type="text/css"></head><body class="UsePageBg"><p align="center"><font size=4>用户信息</font></p><form action="<?php echo $php_self; ?>" method=get>查询条件:<select name=sele><option value="id" selected>用户序号</option><option value="UserName" >用户名</option><option value="Balance" >用户佘额</option></select><select name=match><option value="=" selected>精确查询</option><option value="like">模糊查询</option></select> <input type=text name="key" id=key><input type=submit value=提交></form><?php include ("config.php");if($key1=="") { $record = mysql_query("select * from radius.radcheck"); $result = mysql_query("SELECT id,UserName,Balance,Gratis FROM radius.radcheck ORDER BY id DESC LIMIT $StartRow,$PageSize"); }elseif($match1=="="){ $record = mysql_query("select * from radius.radcheck where $sele1 = '$key1' "); $result = mysql_query("SELECT id,UserName,Balance,Gratis FROM radius.radcheck where $sele1 = '$key1' ORDER BY id DESC LIMIT $StartRow,$PageSize"); }elseif($match1=="like"){ $record = mysql_query("select * from radius.radcheck where $sele1 like '%$key1%' "); $result = mysql_query("SELECT id,UserName,Balance,Gratis FROM radius.radcheck where $sele1 like '%$key1%' ORDER BY id DESC LIMIT $StartRow,$PageSize"); } $RecordCount = mysql_num_rows($record); $MaxPage = $RecordCount % $PageSize; if($RecordCount % $PageSize == 0){ $MaxPage = $RecordCount / $PageSize; }else{ $MaxPage = ceil($RecordCount / $PageSize); }?><table cellspacing=0 bordercolordark=#FFFFFF width="100%" bordercolorlight=#000000 border=1 align="center" cellpadding="2" class="InternalHeader"> <font size=4><?php print "总共$RecordCount record(s) 条记录 - 当前页: $PageNo of $MaxPage" ?></font></table><table cellspacing=0 bordercolordark=#FFFFFF width="100%" bordercolorlight=#000000 border=1 align="center" cellpadding="2"> <tr bgcolor="#6b8ba8" style="color:FFFFFF"> <tr> <td align=center class="InternalHeader">记录序号</td> <td align=center bgcolor="#6b8ba8" style="color:FFFFFF" class="InternalHeader" >用户名</td> <td align=center bgcolor="#6b8ba8" style="color:FFFFFF" class="InternalHeader" >用户佘额</td> <td align=center bgcolor="#6b8ba8" style="color:FFFFFF" class="InternalHeader" >用户标识</td> <td align=center bgcolor="#6b8ba8" style="color:FFFFFF" class="InternalHeader" >用户性质</td> </tr></tr><?php$i = 1;while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $bil = $i + ($PageNo-1)*$PageSize;?> <tr> <td ><?php echo $row[0] ?></td> <td ><?php echo $row[1] ?></td> <td ><?php echo $row[2] ?></td> <td ><?php echo $row[3] ?></td> <td ><?php if($row[3]==1){ echo "免费用户";}else{ echo "会费用户";} ?></td> </tr><?php $i++;}?></table><br><table width="100%" border="0" class="InternalHeader"> <tr> <td> <div align="center"> <?php echo "<font size=4>"; if($PageNo != 1){ $PrevStart = $PageNo - 1; print "<a href=myphp.php?PageNo=1>第一页 </a>: "; print "<a href=myphp.php?PageNo=$PrevStart>上一页 </a>"; } print " [ "; $c = 0; for($c=$CounterStart;$c<=$CounterEnd;$c++){ if($c < $MaxPage){ if($c == $PageNo){ if($c % $PageSize == 0){ print "$c "; }else{ print "$c ,"; } }elseif($c % $PageSize == 0){ echo "<a href=myphp.php?PageNo=$c>$c</a> "; }else{ echo "<a href=myphp.php?PageNo=$c>$c</a> ,"; }//END IF }else{ if($PageNo == $MaxPage){ print "$c "; break; }else{ echo "<a href=myphp.php?PageNo=$c>$c</a> "; break; }//END IF }//END IF }//NEXT echo "] "; if($PageNo < $MaxPage){ $NextPage = $PageNo + 1; echo "<a href=myphp.php?PageNo=$NextPage>下一页</a>"; } if($PageNo < $MaxPage){ $LastRec = $RecordCount % $PageSize; if($LastRec == 0){ $LastStarrecord = $RecordCount - $PageSize; } else{ $LastStarrecord = $RecordCount - $LastRec; } print " : "; echo "<a href=myphp.php?PageNo=$MaxPage>最后一页</a>"; } echo "</font>"; ?> </div> </td> </tr></table><?php #mysql_free_result($result); #mysql_free_result($record);?></body></html> 自己打印$StartRow,$PageSize看一下是什么结果 php如何比较两个数组是否相等 求解,关于字符串处理的问题!怎么从字符串中找联系 PHP如何实现将一幅图像用字符显示在网页上呢? 怎么返回结果? 初学PHP,请问,PHP5页面间的参数怎么传递? 关于一个PHP页的优化设计问题,请高手指教. 关于sql语句判断与程序判断,哪个更省时省力? 熟悉phorum进来呀! 一般来说,不能创建COM对象的原因有哪些?如何解决? 我想做一个能匹配任何有效的URL的函数,请问怎么写? php如何获取flash中的Url(在线等待。。。。) 怎么限制当前某个IP地址的访问
<?php$PageSize = 10;
$StartRow = 0; if(empty($_GET['PageNo'])){
if($StartRow == 0){
$PageNo = $StartRow + 1;
}
}else{
$PageNo = $_GET['PageNo'];
$StartRow = ($PageNo - 1) * $PageSize;
}
if($PageNo % $PageSize == 0){
$CounterStart = $PageNo - ($PageSize - 1);
}else{
$CounterStart = $PageNo - ($PageNo % $PageSize) + 1;
}
$CounterEnd = $CounterStart + ($PageSize - 1);
$key1=$HTTP_GET_VARS["key"];
$sele1=$_GET['sele'];
$match1=$_GET['match'];
?><html>
<head>
<title>用户信息查询</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head><body class="UsePageBg"><p align="center"><font size=4>用户信息</font></p><form action="<?php echo $php_self; ?>" method=get>
查询条件:
<select name=sele>
<option value="id" selected>用户序号</option>
<option value="UserName" >用户名</option>
<option value="Balance" >用户佘额</option>
</select>
<select name=match>
<option value="=" selected>精确查询</option>
<option value="like">模糊查询</option>
</select>
<input type=text name="key" id=key><input type=submit value=提交>
</form><?php
include ("config.php");
if($key1=="")
{
$record = mysql_query("select * from radius.radcheck");
$result = mysql_query("SELECT id,UserName,Balance,Gratis FROM radius.radcheck ORDER BY id DESC LIMIT $StartRow,$PageSize");
}elseif($match1=="="){
$record = mysql_query("select * from radius.radcheck where $sele1 = '$key1' ");
$result = mysql_query("SELECT id,UserName,Balance,Gratis FROM radius.radcheck where $sele1 = '$key1' ORDER BY id DESC LIMIT $StartRow,$PageSize");
}elseif($match1=="like"){
$record = mysql_query("select * from radius.radcheck where $sele1 like '%$key1%' ");
$result = mysql_query("SELECT id,UserName,Balance,Gratis FROM radius.radcheck where $sele1 like '%$key1%' ORDER BY id DESC LIMIT $StartRow,$PageSize");
}
$RecordCount = mysql_num_rows($record);
$MaxPage = $RecordCount % $PageSize;
if($RecordCount % $PageSize == 0){
$MaxPage = $RecordCount / $PageSize;
}else{
$MaxPage = ceil($RecordCount / $PageSize);
}
?>
<table cellspacing=0 bordercolordark=#FFFFFF width="100%" bordercolorlight=#000000 border=1 align="center" cellpadding="2" class="InternalHeader">
<font size=4><?php print "总共$RecordCount record(s) 条记录 - 当前页: $PageNo of $MaxPage" ?></font>
</table>
<table cellspacing=0 bordercolordark=#FFFFFF width="100%" bordercolorlight=#000000 border=1 align="center" cellpadding="2">
<tr bgcolor="#6b8ba8" style="color:FFFFFF">
<tr>
<td align=center class="InternalHeader">记录序号</td>
<td align=center bgcolor="#6b8ba8" style="color:FFFFFF" class="InternalHeader" >用户名</td>
<td align=center bgcolor="#6b8ba8" style="color:FFFFFF" class="InternalHeader" >用户佘额</td>
<td align=center bgcolor="#6b8ba8" style="color:FFFFFF" class="InternalHeader" >用户标识</td>
<td align=center bgcolor="#6b8ba8" style="color:FFFFFF" class="InternalHeader" >用户性质</td>
</tr>
</tr>
<?php
$i = 1;while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$bil = $i + ($PageNo-1)*$PageSize;?>
<tr>
<td ><?php echo $row[0] ?></td>
<td ><?php echo $row[1] ?></td>
<td ><?php echo $row[2] ?></td>
<td ><?php echo $row[3] ?></td>
<td ><?php if($row[3]==1){
echo "免费用户";}else{
echo "会费用户";}
?></td>
</tr>
<?php
$i++;
}?>
</table><br>
<table width="100%" border="0" class="InternalHeader">
<tr>
<td> <div align="center">
<?php
echo "<font size=4>";
if($PageNo != 1){
$PrevStart = $PageNo - 1;
print "<a href=myphp.php?PageNo=1>第一页 </a>: ";
print "<a href=myphp.php?PageNo=$PrevStart>上一页 </a>";
}
print " [ ";
$c = 0;
for($c=$CounterStart;$c<=$CounterEnd;$c++){
if($c < $MaxPage){
if($c == $PageNo){
if($c % $PageSize == 0){
print "$c ";
}else{
print "$c ,";
}
}elseif($c % $PageSize == 0){
echo "<a href=myphp.php?PageNo=$c>$c</a> ";
}else{
echo "<a href=myphp.php?PageNo=$c>$c</a> ,";
}//END IF
}else{
if($PageNo == $MaxPage){
print "$c ";
break;
}else{
echo "<a href=myphp.php?PageNo=$c>$c</a> ";
break;
}//END IF
}//END IF
}//NEXT echo "] "; if($PageNo < $MaxPage){
$NextPage = $PageNo + 1;
echo "<a href=myphp.php?PageNo=$NextPage>下一页</a>";
}
if($PageNo < $MaxPage){
$LastRec = $RecordCount % $PageSize;
if($LastRec == 0){
$LastStarrecord = $RecordCount - $PageSize;
}
else{
$LastStarrecord = $RecordCount - $LastRec;
} print " : ";
echo "<a href=myphp.php?PageNo=$MaxPage>最后一页</a>";
}
echo "</font>";
?>
</div>
</td>
</tr>
</table>
<?php
#mysql_free_result($result);
#mysql_free_result($record);
?>
</body>
</html>