2010-12-02 449 views
0

我有一個簡單的MySQL查詢,根據兩個要求從表中選擇所有列。MySQL select查詢

`$dbSearchRecords = mysql_query("SELECT * FROM booking WHERE BookingID = '$JobNo_search' AND Date BETWEEN '$DateFrom_search' AND '$DateTo_search'")` 

我想獲得查詢來搜索一個或兩個要求。 WHERE BookingID ='$ JobNo_search'與'$ DateFrom_search'AND'$ DateTo_search'之間的日期

目前所有參數都需要存在才能得到結果,我需要能夠僅搜索BookinID或日期範圍。

乾杯傢伙。

回答

1

怎樣......

$dbSearchRecords = mysql_query(

    "SELECT * FROM booking 
    WHERE BookingID = '$JobNo_search' 
    OR (Date BETWEEN '$DateFrom_search' AND '$DateTo_search') 
    OR itemid = $itemID 
    OR job_no = $job_no 
    OR rego = $rego 
    " 

) 

的OR工作作爲AND/OR。

+0

歡呼兄弟。你知道你讓我想起我的伴侶cosmicdog :) – 2010-12-03 03:00:19