php中的mysql查询有问题吗?

时间:2015-05-06 09:32:35

标签: php mysql

$sql = "SELECT s1.roomtype, s1.roomno, s1.checkin,s1.checkout FROM
guestrocordtransac s1
JOIN guestrocord s2
ON s1.roomtype = s2.roomtype  AND s1.roomno != s2.roomno 
WHERE s1.checkin = '".$date1."' BETWEEN  s2.checkin  = '".$date1."' AND s2.checkout='".$date2."' "; 

我不知道它出了什么问题..我必须检查房型,房间号,登记入住和退房日期之间......

我从表单中获取roomttype,roomno,checkin,checkout值。现在我必须将它与数据库进行比较。

1 个答案:

答案 0 :(得分:1)

下面

$sql = "SELECT s1.roomtype, s1.roomno, s1.checkin,s1.checkout FROM
guestrocordtransac s1
JOIN guestrocord s2
ON s1.roomtype = s2.roomtype  AND s1.roomno != s2.roomno 
WHERE s1.checkin = '".$date1."' BETWEEN  s2.checkin  = '".$date1."' AND s2.checkout='".$date2."' ";

您的where子句中的语法无效,因为您不应检查between个操作数中的相等性。这应该可以解决问题:

$sql = "SELECT s1.roomtype, s1.roomno, s1.checkin,s1.checkout FROM
guestrocordtransac s1
JOIN guestrocord s2
ON s1.roomtype = s2.roomtype  AND s1.roomno != s2.roomno 
WHERE s1.checkin = '".$date1."' BETWEEN  '".$date1."' AND '".$date2."' ";

详细了解between here