/****** **一个简单的搜索 *****/ //将搜索语句加到最开始的查询语句里面;从而实现了代码的精简 $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实现搜索功能代码的详细内容。
