2012-01-11 56 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