Home > Database > Mysql Tutorial > sql 多关键字搜索

sql 多关键字搜索

WBOY
Release: 2016-06-07 14:57:31
Original
1595 people have browsed it

sql多关键字搜索 无 if(count($newstr)==1){//如果数组的元素个数为1个,则按单个条件进行查询 $sql = "select * from tb_info where title like '%".$newstr[0]."%' or content like '%".$newstr[0]."%'order by id desc ";}else{//合并查询结果集for($i=0;$

sql 多关键字搜索
		if(count($newstr)==1){					//如果数组的元素个数为1个,则按单个条件进行查询
			 $sql = "select * from tb_info where title like '%".$newstr[0]."%' or content like '%".$newstr[0]."%'order by id desc ";
		}else{
			
			//合并查询结果集
			for($i=0;$i<count($newstr);$i++){
				$sql0.=" title like '%".trim($newstr[$i])."%'"." or";	
			}
			for($j=0;$j<count($newstr);$j++){
				$sql1.=" content like '%".trim($newstr[$j])."%'"." or";	
			}
			$sql1=substr($sql1,0,-3);				//去掉最后一个“or”		
			$sql="select * from tb_info where".$sql0.$sql1." order by id desc";
		
		}
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template