2012-01-11 22 views
3

我有一個SQL語句:其中OR MySQL在哪兒 - 有兩個MySQL查詢的WHERE子句

$sql =" SELECT DISTINCT 
      scr.* 
     FROM scr 
      LEFT JOIN `users` ON `users`.user_id=scr.user_id 

     WHERE $email_filter LOWER(scr.genre) LIKE '%$search_word_fix%' **HERE** $psez protage $wwc $prevoption $locatio $rats $rat1 $rat2 $rat3 $rat4   
     GROUP by scr.sp_name 
     ORDER BY scr.grade DESC"; 

當我添加低(scr.classification)就像 「這裏」 '%$ search_word_fix%' 它不顯示正確的結果。 我正在考慮像(其中scr.genre =「searchkeyword」和其他過濾器在這裏)或(其中scr.classification =「searchkeyword」和其他過濾器在這裏)

+0

是組順序,你需要一個'和'或'你WHERE條件之間的'或' '條款。 – FrustratedWithFormsDesigner 2012-01-11 20:59:02

+1

我不知道您的腳本:但在將它傳遞給查詢之前,請確保清理任何用戶輸入。 – TimWolla 2012-01-11 20:59:07

+1

'mysql_real_escape_string'!用它! – Halcyon 2012-01-11 20:59:17

回答

7

只指定哪裏一次。附加條款中指定只是「或」與「和」

使用parans到操作

where (scr.genre = "searchkeyword" and other filters here) 
OR (scr.classification ="searchkeyword" and other filters here) 
+0

是的,這完美地工作謝謝你 – cppit 2012-01-11 21:13:34