字體:  

PHP5+MYSQL5使用dreamweaver8的語法問題

h055971328 發表於: 2009-7-23 10:45 來源: ADJ網路控股集團


我在製作一個中西藥查詢系統
它有中藥(herb)和西藥(drug)兩個查詢欄位
colherb為接受中藥欄位傳來的值,預設值1,執行階段值$_GET['herb']
coldrug為接受西藥欄位傳來的值,預設值1,執行階段值$_GET['drug']
我為此寫了兩個語法,分別讓它可以單向查詢(其中一個欄位為空時)和交叉查詢(2個欄位都有資料時)
使用if...else...
寫入資料集(查詢)的SQL欄位裡

if ($_GET['drug'] or $_GET['herb'] == NULL)   {   
SELECT *
FROM medicine
WHERE TCMCName = 'colherb' OR TCMEName = 'colherb' OR TCMGName = 'colherb'  UNION 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')}

可是按F12測試網頁輸入資料後卻出現
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\AppServ\www\cawm\Search.php on line 12

請問我的語法哪邊有錯誤呢?
附上Search.php on line 12的程式碼

$query_show = sprintf("if ($_GET['drug'] or $_GET['herb'] == NULL)   {    SELECT * FROM medicine WHERE TCMCName = '%s' OR TCMEName = '%s' OR TCMGName = '%s'  UNION SELECT * FROM medicine WHERE `Western Medicine` = '%s' }                                               else  { SELECT * FROM medicine WHERE TCMCName in ('%s') and `Western Medicine` in     ('%s')  UNION SELECT * FROM medicine WHERE TCMEName in ('%s') and     `Western Medicine` in ('%s')  UNION SELECT * FROM medicine WHERE TCMGName in   ('%s') and `Western Medicine` in ('%s')}", $colherb_show,$colherb_show,$colherb_show,$coldrug_show,$colherb_show,$coldrug_show,$colherb_show,$coldrug_show,$colherb_show,$coldrug_show);
拜託大家...我真的不知道哪邊出問題>''<