Board logo

標題: [求助] PHP+MYSQL查詢資料前使用條件判斷 [打印本頁]

作者: h055971328    時間: 2009-7-9 10:36     標題: PHP+MYSQL查詢資料前使用條件判斷

我想做一個中西藥查詢系統
它有中藥和西藥兩個欄位
它現在的問題是
如何在我輸入資料後
先執行判斷
判斷中藥是否為空,西藥是否為空,或兩者不為空
再執行查詢
謝謝大家的幫忙!!

這是我寫的語法..但不能用...會出現錯誤
if ('coldrug' == null){ SELECT *
FROM medicine
WHERE TCMCName = 'colherb'  UNION SELECT * FROM medicine WHERE TCMEName = 'colherb'  UNION SELECT * FROM medicine WHERE TCMGName = 'colherb';}
elseif('colherb' == null){ SELECT * FROM medicine WHERE `Western Medicine` = 'coldrug';}
else{ SELECT * FROM medicine WHERE TCMCName in ('colherb') and `Western Medicine` in ('coldrug')  UNION SELECT * FROM medicine WHERE TCMEName in ('colherb') and `Western Medicine` in ('coldrug')  UNION SELECT * FROM medicine WHERE TCMGName in ('colherb') and `Western Medicine` in ('coldrug');}




歡迎光臨 ADJ網路實驗室 (http://dz.adj.idv.tw/) Powered by Discuz! 6.0.0