如何使用php mysql条件选择日期之间的数据?

时间:2015-05-19 11:27:59

标签: php mysql

我已经给出了这样的查询:

$sql12 = "select roomno from guestrocordtransac where checkin between '".$format_checkin."' and '".$format_checkout."' and roomtype='".$roomtype."'";

表:的 guestrocordtransac

id roomno roomtype  checkin          checkout

1   101    Seashell 2015-05-20       2015-05-28

2   202    Seashore  2015-05-15      2015-05-30

表2:的 roominfo

id  roomno  roomtype 

 1   101    Seashell 

 2   102    Seashell 

 3   201    Seashore

 4  202    Seashore

当我尝试在php中使用查询时,我将获得一个空值...我不知道查询发生了什么..

在mysql中尝试时,我的记录少了

1 个答案:

答案 0 :(得分:2)

使用此:

$sql12 = "select roomno from guestrocordtransac where checkin >= '".$format_checkin."' and checkin <= '".$format_checkout."' and roomtype='".$roomtype."'";