woff 發表於 2012-12-31 00:41:24

MYSQL如何搜尋字串部分又需要比對使用者的權限選出多筆資料

假設在MYSQL同一表裡,需要用到搜尋字串部分又需要比對使用者的權限
就需要使用很多AND 及 OR

但是這很容易弄錯
所以來說明一下 $str="SELECT * FROM net_costomer WHERE (costomernum like '%$scostomer%' OR name like '%$scostomer%' OR phone1 like '%$scostomer%' OR phone2 like '%$scostomer%' OR phone3 like '%$scostomer%' OR rname like '%$scostomer%' OR address1 like '%$scostomer%' OR address2 like '%$scostomer%') AND (fuid='".$_SESSION."' OR suid='".$_SESSION."' OR suid1='".$_SESSION."' OR suid2='".$_SESSION."' OR suid3='".$_SESSION."' OR suid4='".$_SESSION."')";
這裡面有搜尋字串部份
like '%$scostomer%'

也有比對全縣部份才能撈出資料
fuid='".$_SESSION."'

所以AND兩邊都要加上( )

這樣就不會出錯了
頁: [1]
查看完整版本: MYSQL如何搜尋字串部分又需要比對使用者的權限選出多筆資料