时间:2021-07-01 10:21:17 帮助过:3人阅读
/****** **一个简单的搜索 *****/ //将搜索语句加到最开始的查询语句里面;从而实现了代码的精简 $news_sql = "SELECT * from books where 1=1 ".$searchAddSql." order by book_number "; // $searchAddSql最开始是为空的,如果用户输入了搜索条件,$searchAddSql 就会变成一个包涵查询语句的字符串: //先判定用户是否输入了搜索条件 if(isset($_GET["searchText"])) { $searchText = $_GET["searchText"]; $searchAddSql = $searchAddSql." and (book_number like '%".$searchText."%' or book_name like '%".$searchText."%' or book_sum like '%".$searchText."%' or book_author like '%".$searchText."%')"; } //最开始的$news_sql = "SELECT * from books where 1=1 ".$searchAddSql." order by book_number ";就会变成: $news_sql="SELECT * from books where 1=1 and (book_number like '%中%' or book_name like '%中%' or book_sum like '%中%' or book_author like '%中%' ) order by book_number"; //相当于重置了查询语句,从而达到搜索的目地
相关推荐:
PHP简单搜索功能实现讲解
实例讲解JS如何实现百度搜索功能
php搜索功能
以上就是php实现搜索功能代码的详细内容,更多请关注Gxl网其它相关文章!