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