TShopping

 找回密碼
 註冊
搜索
查看: 2401|回復: 0
打印 上一主題 下一主題

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

[複製鏈接]
跳轉到指定樓層
1#
發表於 2012-12-31 00:41:24 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
 
Push to Facebook
假設在MYSQL同一表裡,需要用到搜尋字串部分又需要比對使用者的權限
就需要使用很多AND 及 OR

但是這很容易弄錯
所以來說明一下
  1. $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[uid]."' OR suid='".$_SESSION[uid]."' OR suid1='".$_SESSION[uid]."' OR suid2='".$_SESSION[uid]."' OR suid3='".$_SESSION[uid]."' OR suid4='".$_SESSION[uid]."')";
複製代碼
這裡面有搜尋字串部份
like '%$scostomer%'

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

所以AND兩邊都要加上( )

這樣就不會出錯了

 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-4-19 14:33 , Processed in 0.059260 second(s), 22 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表