实现PHP搜索加分页
2016-10-12 00:00
369 查看
分页显示是浏览大量数据的一种方法。对于初学者来说常常对这个问题摸不着头绪,因此特地撰写此文对这个问题进行详细的讲解,力求让看完这篇文章的朋友在看完以后对于分页显示的原理和实现方法有所了解。
所有示例代码均使用php编写。
所谓分页显示,也就是将数据库中的结果集人为的分成一段一段的来显示。
请详细阅读以下代码,自己调试运行一次,最好把它修改一次,加上自己的功能。
希望本文所述对大家PHP程序设计有所帮助。
.net搜索查询并实现分页实例
jquery+json实现的搜索加分页效果
ThinkPHP让分页保持搜索状态的方法
Ajax搜索结果页面下方的分页按钮的生成
BootStrap Table 分页后重新搜索问题的解决办法
使用Java的Lucene搜索工具对检索结果进行分组和分页
ajax结合豆瓣搜索结果进行分页完整代码
所有示例代码均使用php编写。
所谓分页显示,也就是将数据库中的结果集人为的分成一段一段的来显示。
请详细阅读以下代码,自己调试运行一次,最好把它修改一次,加上自己的功能。
$wherelist=array(); $urlist=array(); if(!empty($_GET['title'])) { $wherelist[]=" title like '%".$_GET['title']."%'"; $urllist[]="title=".$_GET['title']; } if(!empty($_GET['keywords'])) { $wherelist[]=" keywords like '%".$_GET['keywords']."%'"; $urllist[]="keywords=".$_GET['keywords']; }if(!empty($_GET['author'])) { $wherelist[]=" author like '%".$_GET['author']."%'"; $urllist[]="author=".$_GET['author']; } $where=""; if(count($wherelist)>0) { $where=" where ".implode(' and ',$wherelist); $url='&'.implode('&',$urllist); } //分页的实现原理 //1.获取数据表中总记录数 $sql="select count(*) from news $where "; $result=mysql_query($sql); $totalnum=mysql_num_rows($result); //每页显示条数 $pagesize=5; //总共有几页 $maxpage=ceil($totalnum/$pagesize); $page=isset($_GET['page'])?$_GET['page']:1; if($page <1) { $page=1; } if($page>$maxpage) { $page=$maxpage; } $limit=" limit ".($page-1)*$pagesize.",$pagesize"; $sql1="select * from news {$where} {$limit}"; //$sql1="select * from news {$where} {$limit}"; $res=mysql_query($sql1); ?> <form action="searchpage.php" method="get"> 标题:<input type="text" name="title" value="<?php echo $_GET['title']?>" size="8"> 关键字<input type="text" name="keywords" value="<?php echo $_GET['keywords']?>" size="8"> 作者:<input type="text" name="author" value="<?php echo $_GET['author']?>" size="8"> <input type="button" value="查看全部" onclick="window.location='searchpage.php'"> <input type="submit" value="搜索"> </form> <table border="1" width="1000" align="center"> <tr> <td>编号</td> <td>标题</td> <td>关键字</td> <td>作者</td> <td>日期</td> <td>内容</td> </tr> <?php while($row= mysql_fetch_assoc($res)){?> <tr> <td><?php echo $row['id'] ?></td> <td><?php echo $row['title'] ?></td> <td><?php echo $row['keywords'] ?></td> <td><?php echo $row['author'] ?></td> <td><?php echo date("Y-m-d H:i:s",$row['addtime']) ?></td> <td><?php echo $row['content'] ?></td> </tr> <?php }?> <tr> <td colspan="6"> <?php echo " 当前{$page}/{$maxpage}页 共{$totalnum}条"; echo " <a href='searchpage.php?page=1{$url}'>首页</a> "; echo "<a href='searchpage.php?page=".($page-1)."{$url}'>上一页</a>"; echo "<a href='searchpage.php?page=".($page+1)."{$url}'>下一页</a>"; echo " <a href='searchpage.php?page={$maxpage}{$url}'>尾页</a> "; ?> </td> </tr> </table>
希望本文所述对大家PHP程序设计有所帮助。
您可能感兴趣的文章:
Thinkphp搜索时首页分页和搜索页保持条件分页的方法.net搜索查询并实现分页实例
jquery+json实现的搜索加分页效果
ThinkPHP让分页保持搜索状态的方法
Ajax搜索结果页面下方的分页按钮的生成
BootStrap Table 分页后重新搜索问题的解决办法
使用Java的Lucene搜索工具对检索结果进行分组和分页
ajax结合豆瓣搜索结果进行分页完整代码
相关文章推荐
- 实现PHP搜索加分页
- PHP+jQuery寥寥几行代码轻松实现百度搜索那样的无刷新PJAX的分页列表和导航链接
- 用PHP实现ODBC数据分页显示一例
- PHP实现分页的一个示例
- PHP分页实现
- PHP中分页的实现
- php+ajax+xml 实现无刷新分页
- Java Script与PHP配合实现智能化的搜索界面
- 用PHP实现ODBC数据分页显示一例
- php分页实现方法
- PHP+Ajax 实现分页技术
- PHP中搜索结果分页的几种方法
- 用PHP实现ODBC数据分页显示一例
- 在Oracle中实现搜索分页查询
- XML+Javascript 实现静态页搜索及分页功能
- PHP&MYSQL分页原理及实现
- Php+SqlServer实现分页显示
- 在Oracle中实现搜索分页查询
- php+SQL实现分页
- php,ajax实现分页