2017-08-30 86 views
-2

種類先生的這是正確的mysqli聲明,當我想要搜索某些日期之間的數據。mysqli聲明LIKE和BETWEEN

Ex。我輸入「pending」,即reservationstatus,然後從日期選擇器中選擇(2017/8/28),日期選擇器將變爲from_date並選擇另一個日期(2017/8/30),這將成爲to_date。

結果必須是從2017/8/28到2017/8/30日期的待定預訂狀態。

在此先感謝希望你能幫助我。

$query = " 
    SELECT * FROM reservations 
    WHERE firstname LIKE '".$search."' 
    OR lastname LIKE '".$search."' 
    OR emailaddress LIKE '%".$search."%' 
    OR contactnumber LIKE '%".$search."%' 
    OR speaker LIKE '".$search."' 
    OR topic LIKE '%".$search."%' 
    OR location LIKE '%".$search."%' 
    OR audience LIKE '%".$search."%' 
    OR count LIKE '%".$search."%' 
    OR time LIKE '%".$search."%' 
    OR date LIKE '%".$search."%' 
    OR reservationdate LIKE '%".$search."%' 
    OR reservationtime LIKE '%".$search."%' 
    OR reservationstatus LIKE '%".$search."%' 
    AND date BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."'"; 

回答

2
$query = " 
    SELECT * FROM reservations 
    WHERE (firstname LIKE '".$search."' 
    OR lastname LIKE '".$search."' 
    OR emailaddress LIKE '%".$search."%' 
    OR contactnumber LIKE '%".$search."%' 
    OR speaker LIKE '".$search."' 
    OR topic LIKE '%".$search."%' 
    OR location LIKE '%".$search."%' 
    OR audience LIKE '%".$search."%' 
    OR count LIKE '%".$search."%' 
    OR time LIKE '%".$search."%' 
    OR date LIKE '%".$search."%' 
    OR reservationdate LIKE '%".$search."%' 
    OR reservationtime LIKE '%".$search."%' 
    OR reservationstatus LIKE '%".$search."%') 
    AND date BETWEEN '".$_POST["from_date"]."' 
    AND '".$_POST["to_date"]."'"; 

添加全部或條款功能支架會解決的bug。

+0

謝謝!!!這行得通。 – Red

+0

太好了。將答案設爲已接受。 –

+0

是的,它說11秒去。即時消息等待 – Red