全站查询和分页显示——在线留言板2
来源:互联网 发布:怎么看台湾网站知乎 编辑:程序博客网 时间:2024/05/16 14:31
全站搜索这里利用的技术是先把数据库的所有内容都导出,然后用字符串匹配的技术找到相应的数据存到一个数组里面去。
还是像往常一样,自己就不要说些乱七八糟的了,直接上代码:
search模块:
<!--search.php:站内搜索函数---------------------><?php require_once("sys_conf.inc"); /************************************************** /*功能:查询content字段包含$keyword的所有留言记录 /*输入:查询关键字 /*输出:查询数组 /**************************************************/ function search($keyword,$content) { $count=count($content); $j=0; $ArrSearch=array(); //结果数组 for ($i=0;$i<$count;$i++) { if (ereg($keyword,$content[$i]))//判断cotent[$i]中是否含有$keyword关键字,如果有,则条件成立 { //把关键字用红颜色突出显示,并放入结果数组 $ArrSearch[$j]=str_replace($keyword,"<font color=red><b>$keyword</b></font>",$content[$i]); $j++; } } return $ArrSearch; } /************************************************** /*功能:查询content字段包含$keyword的所有留言记录的rid /*输入:查询关键字 /*输出:rid数组 /**************************************************/ function searchid($keyword,$rid,$content) { $count=count($content); $j=0; $Arrid=array(); //结果数组 for ($i=0;$i<$count;$i++) { if (ereg($keyword,$content[$i]))//判断cotent[$i]中是否含有$keyword关键字,如果有,则条件成立 { $Arrid[$j]=$rid[$i]; $j++; } } return $Arrid; } //初始化 $one_page_line=10; //每页的最大记录数 $content=array(); //数组,包含所有记录的content属性内容 $id=array(); //数组,包含所有记录的rid属性内容 $ArrSearch=array(); //数组,包含查询结果 $Arrid=array(); //数组,包含查询结果记录的编号 //查询数据库,获取$content值 $link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD); mysql_select_db($DBNAME); $str="select rid,content from guestbook;"; $result=mysql_query($str); //循环将数据库中值写入数组 $i=0; while(list($rid,$con)=mysql_fetch_row($result)) { $content[$i]=$con; //print($con); $id[$i]=$rid; $i++; } mysql_close($link_id); //调用search()函数,查询关键字 if (isset($_POST["search"]) and isset($_POST["keyword"]) and $_POST["keyword"]!="") { $ArrSearch=search($_POST["keyword"],$content); $Arrid=searchid($_POST["keyword"],$id,$content); } //输出全部数据 else { //print_r($content); $ArrSearch=$content; //print_r($ArrSearch); $Arrid=$id; } //print_r($ArrSearch); //print_r($Arrid); $count =count($ArrSearch);//echo ($count);?>
显示模块:这里的话主要是有一些细小的知识点,需要自己来仔细研究一下。
<!--booklist.php:用户留言列表----------------------------><?php include "search.php"?><html> <head> <title>站内查询</title> </head> <body> <?php include "head.html"?> <table width="68%" border="5px;"> <tr> <td> <?php $one_page_line=5; $int_page_count=$count; //总条数; $int_page_num=ceil($int_page_count/$one_page_line);//总页数;// echo $int_page_num; echo "<font color=#CC33FF>分页:</font>"; for ($i=1;$i<=$int_page_num;$i++) { if (!isset($_POST["search"]) and !isset($_POST["keyword"])) echo "<a href=booklist.php?page=$i>".$i."</a> "; } echo "</font>"; if (isset($_POST["search"]) and isset($_POST["keyword"]) and $_POST["keyword"]!="") { echo "<br><center>"; echo "<a href=booklist.php?search=".$_POST["search"]."&keyword=".$_POST["keyword"]."&page=$i>".$i."</a> "; echo "下面的留言中包含关键字<font color=red><b>".$_POST["keyword"]."</b></font>共<font color=red>".$count."</font>条</center>"; } ?> </td> <td><p align=right>共有<font color=red><?echo "$count"?></font>条</p></td> </tr> </table> <table width="68%" border="0" align="center"> <? if (!isset($_GET['page'])) $page=1; else $page=$_GET['page']; $text=""; $begin_line=$int_page_count-($page-1)*$one_page_line; if ($begin_line<$one_page_line) $one_page_line=$begin_line; for ($j=$begin_line;$j>($begin_line-$one_page_line);$j--) { echo "<tr><td align=right colspan=2><a href=replylist.php?&recordid=".$Arrid[$j-1].">查看回复</a> <a href=reply.php?task=reply&recordid=".$Arrid[$j-1].">回复</a> <a href=update.php?recordid=".$Arrid[$j-1].">编辑</a> <a href=delete.php?recordid=".$Arrid[$j-1].">删除</a> 第<font color=red>$j</font>条</td></tr>"; print_r ($ArrSearch[$j-1]); } ?> </table> <p align=center><a href="add.php">插入留言</a></p> <p align=center><a href="#" onclick=history.back()>返 回</a></p> </body></html>
0 0
- 全站查询和分页显示——在线留言板2
- 留言板如何分页显示
- 删除留言和更新留言——在线留言板3
- 分页查询:在线和离线
- 简易在线留言板(上)——树洞留言板
- 简易在线留言板(下)——树洞留言板
- ssh分页查询和显示
- php分页显示类——在线拍卖行(1)
- 增加留言版块——在线留言板1
- 添加评论,查看评论等——在线留言板4
- 简易在线留言板(中)——树洞留言版
- JAVA高级【4.8】《Java核心技术2》数据库-JavaWeb分页显示内容——数据库分页查询
- 在线留言板
- JSP实现留言板的JavaBean类和分页显示的源码
- PHP和MYSQL查询和分页显示
- 留言板分页
- ios Sqlite显示和分页查询
- java留言板分页问题和走马灯问题
- Java开发中的23种设计模式详解(转)
- activity的android:name所指的Activity实现类的简写问题
- 最长上升子序列
- linux 命令笔记
- hadoop倒排索引
- 全站查询和分页显示——在线留言板2
- cocos2d-x怎么新建项目
- 【leetcode】Binary Tree Level Order Traversal
- 【转】世界最著名大学教育向我们开放了!!!!!(非常珍贵的资源!!)
- 合A*算法
- Qt学习之路之解决unable to find a qt build,to solve this problem specify a qt build
- 黑马程序员——[C语言]基本运算符
- 项目不报错,但是数据添加不到数据库中
- LeetCode | Sum Root to Leaf Numbers