当搜索日期落在from_date和to_date mysql

时间:2015-11-30 10:56:35

标签: php mysql

我有一张基于from_dateto_date的房间费用表:

db的格式:

planid | roomtype_id | capacity_id | hotel_id |date_from | date_to | cost

我希望根据到货日期获得房间费用,当arrival_date介于date_fromdate_to

之间时,该日期会存储在输入字段中

我的代码:

$result1 = mysql_query("SELECT * FROM room_price WHERE roomtype_id = '$roomtype_id' AND capacity_id = '$capacity_id' AND hotel_id = '$hotel_id' AND date_from '$date' BETWEEN date_from AND date_to");

查询没有给出任何输出。

2 个答案:

答案 0 :(得分:2)

问题是,你的\在mysql表colum中使用了两个日期,所以你必须检查我给出的代码如下:

$result1 = mysql_query("SELECT * FROM room_price WHERE roomtype_id = '$roomtype_id' AND capacity_id = '$capacity_id' AND hotel_id = '$hotel_id' AND date_from >='$date' And date_to<=$date");

答案 1 :(得分:0)

尝试此查询:

$result1 = mysql_query("SELECT * FROM room_price WHERE roomtype_id = '$roomtype_id' AND capacity_id = '$capacity_id' AND hotel_id = '$hotel_id' AND BETWEEN 'your_from_Date' AND 'your_to_date'");