利用在查询语句中加入模糊查询的条件以达到关键字模糊搜索的目的:like+通配符(% _)
<form>关键字:<input type="text" name="keyword" value="" /><input type="submit" value="搜索" /></form> <?php //需要将sql查询语句改为:$sql="select * from table_name where username like '%$keyword%' order by id".$limit; $keyword=$_GET['keyword']; if (empty($keyword)){ $where=''; $kword=''; }else{ $where=" where username like '%".$keyword."%'"; $kword='&keyword='.$keyword; } //需更改分页制作以及显示数据内容的查询语句 $sql01="select count(*) from table_name".$where; $sql="select * from table_name".$where." order by id desc".$limit; ?> <!--修改分页的超链接--> <a href="?page=1<?php echo $kword;?>">首页</a> <a href="?page=<?php echo ($page_num-1).$kword;?>">上一页</a> <a href="?page=<?php echo ($page_num+1).$kword;?>">下一页</a> <a href="?page=<?php echo ($page_count).$kword;?>">尾页</a>