请教关于PHP对搜索结果进行分页,不能翻页问题(点击下一页会显示全部记录,而不是搜索出来的记录)

cnccctt 2012-09-18 04:48:20
form name="form1" method="GET" action="">
<table width="98%" height="38" border="1" cellpadding="1" cellspacing="0" bordercolor="#FFFFFF"

bgcolor="#9ECFEE" class="tableBorder_gray">
<tr>
<td align="center">
 <img src="Images/search.gif" width="37" height="29"></td>
<input name="key1" type="text" id="key1" size="50">
<input name="Submit" type="submit" class="btn_grey" value="查询"></td>


$key1=$_GET[key1];


$pagesize1=10;
$total1=mysql_num_rows(mysql_query("select b.*,c.name as bookcasename,p.pubname,t.typename from tb_bookinfo b left

join tb_bookcase c on b.bookcase=c.id join tb_publishing p on b.ISBN=p.ISBN join tb_booktype t on b.typeid=t.id

where $f like '%$key1%' ORDER BY `id` DESC"));
$pagecount1=ceil($total1/$pagesize1);

if ($total1<=$pagesize1){
$pagecount1=1;
}
if(($total1%$pagesize1)!=0){
$pagecount1=intval($total1/$pagesize1)+1;

}else{
$pagecount1=$total1/$pagesize1;

}
if(($_GET[page1])==""){
$page1=1;

}else{
$page1=intval($_GET[page1]);

}



$sql=mysql_query("select b.*,c.name as bookcasename,p.pubname,t.typename from tb_bookinfo b left join tb_bookcase c

on b.bookcase=c.id join tb_publishing p on b.ISBN=p.ISBN join tb_booktype t on b.typeid=t.id where $f like '%

$_REQUEST[key1]%' ORDER BY `id` DESC limit ".($page1-1)*$pagesize1.",$pagesize1");
$info=mysql_fetch_array($sql);
if($info==true){
do{
?>
输出数据库搜索出来的内容
<?php
}while($info=mysql_fetch_array($sql));
}else{
?>
<table width="100%" height="30" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="36" align="center">您检索的信息不存在,请重新检索!</td>
</tr>
</table>
<?php
}
}
}
?>
</table>
</td>
</tr>
</table>
<table>
<tr>
<td>


  
<span class="STYLE3">结果共计<?php echo $total1 ?>条, 当前第<?php echo $page1 ?>页/共<?php echo $pagecount1 ?>

页</span> :  <a href="?page1=<?php echo ($page1 > 1)?($page1 - 1):1;s?>"&<?php echo $_REQUEST[$key1]; ?>

class="word_orange">上一页</a> <a href="?page1=<?php echo ($page1 < ($pagecount1 - 1))?

($page1+1):$pagecount1;?>"&<?php echo $_REQUEST[key1]; ?> class="word_orange">下一页</a> 
...全文
454 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnccctt 2012-09-23
  • 打赏
  • 举报
回复
谢谢大家的热心帮助,我这几天都为这个对搜索的结果分页弄的头疼,还是学艺不精呀,我再试试大家提供的参考办法。
情花有刺 2012-09-21
  • 打赏
  • 举报
回复
这个是我自己写的一段...虽然很不成熟...将就下吧LZ、
function fy($x)
{
$fid=$_GET['fid'];
$sql = "SELECT * FROM `xa_post` WHERE `fid` = '$fid'";
$sql = mysql_query($sql);
$row = mysql_num_rows($sql);
$row = ceil($row/$x);
if($row>1)
{
echo '<ul class="fy">';
for($i=1;$i<=$row;$i++)
{
if($fid==$i)
{
echo '<li class="pid_hover"><a href="class.php?fid='.$fid.'&pid='.$i.'">'.$i.'</a></li>';
}
else
{
echo '<li><a href="class.php?fid='.$fid.'&pid='.$i.'">'.$i.'</a></li>';
}
}
echo '</ul>';
}
}
hlxtg 2012-09-21
  • 打赏
  • 举报
回复
分页传值的 时候跟个标石,识别一下就行了
cnccctt 2012-09-19
  • 打赏
  • 举报
回复
这是我可以正常翻页的代码,各位老师帮忙看看。
<span class="STYLE3">结果共计<?php echo $total1 ?>条, 当前第<?php echo $page1 ?>页/共<?php echo $pagecount1 ?>
页</span> : <a href="?page1=<?php echo ($page1 > 1)?($page1 - 1):1;s?>"class="word_orange">上一页</a> <a href="?page1=<?php echo ($page1 < ($pagecount1 - 1))?
($page1+1):$pagecount1;?>" class="word_orange">下一页</a>
q504196481 2012-09-19
  • 打赏
  • 举报
回复
仔细看看你的判断条件,你就明白了。你少一个条件!!!!!!!!
cnccctt 2012-09-19
  • 打赏
  • 举报
回复
各位大大,是不是我下面翻页代码的问题,xuzuning老师,能不能说详细点。让我好好学习学习。
xuzuning 2012-09-18
  • 打赏
  • 举报
回复
<a href="?page1=<?php echo ($page1 < ($pagecount1 - 1))?$page1+1):$pagecount1;?>"&<?php echo $_REQUEST[key1]; ?>
你只传递了值,没有传递键!
后续的程序如何知道怎样处理呢?
何况引号也有点问题
俺的沙发43222 2012-09-18
  • 打赏
  • 举报
回复
对于该问题,下次建议去掉css,贴出核心代码
俺的沙发43222 2012-09-18
  • 打赏
  • 举报
回复
关于分页问题,请看我的帖子
《sql简单便捷的分页技术》

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧