2012-08-01 42 views
0
$query = "select * from researchsub_form where flag='1' and date between '$date' and '$date1' "; 

我有兩個輸入,日期和DATE1,我必須表明從日期「日期」和標誌=「1」「DATE1」之間數據庫中的數據,對於該予使用SQL查詢,但我想說明的數據時,我只輸入一個日期輸入要麼是「日期」或「日期1」Retrive數據

+0

然後,它是沒有意義的使用'between'和'和'..directly給'其中date =' – 2012-08-01 08:56:54

回答

0

SELECT * FROM researchsub_form其中標誌= '1' 和( '$日期' 和 '$ DATE1' 或日期= '$' 或日期= '$ DATE1' 之間日期)

+0

當我輸入的日期在日期1那麼它將顯示所有條目高達date1from具有標誌數據庫= 1 – M2K 2012-08-02 08:40:10

0

您可以創建你的條件,其中動態。

$query = "select * from researchsub_form where flag='1'"; 

if(isset($date) && isset($date1)) 
    $condition += " and date between '$date' and '$date1'"; 
else if(isset($date)) 
    $condition += " and date > '$date'"; 
else if(isset($date1)) 
    $condition += " and date < '$date1'"; 

$query += $condition; 

或者你可以分配到迄今爲止smalles日期(1753),以DATE1最大的(9999)時,其中一個是空的,但它並不好。