sql 多关键字搜索

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

		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";
		
		}