我有查詢我想出了一個搜索欄。我知道我可以使用或分裂語句來檢查不同的列:MYSQL PHP一次檢查更多一列的聲明
$query = mysql_query('SELECT * FROM PRODUCTS WHERE cats LIKE "%'.$s.'%" OR sub_cats LIKE "%'.$s.'%"');
但如果我要檢查超過2個或三列是重新的方式做這樣的事情,加快了一點東西:
$query_string = explode('&&=',$_GET['q']);
$db_str = 'SELECT * FROM products WHERE name, cats, sub_cats, desc, brand ';
for($x = 0; $x < count($query_string); $x++){
$enc = mysql_real_escape_string($query_string[$x]);
if($x == (count($query_string) -1)){
$db_str .= 'LIKE "%'.$enc.'%"';
}else{
$db_str .= 'LIKE "%'.$enc.'%" ';
}
}
$query = mysql_query($db_str);
我通常在搜索欄中使用POST,但我喜歡給GET一個去看起來更加用戶友好。
您很可能需要[FULLTEXT](http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html)搜索。 –
讓我們現在一起說......'不要使用mysql;它已被棄用。切換到MYSQLI或PDO. – Sablefoste
@Sable Foste你的意思是不推薦使用Mysql,使用PostgreSQL? –