我正在尝试在特定日期签入和结帐之间获取结果。 我得到以下错误:
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '14:00:00 AND b.end <= 2016-03-31 11:00:00' at line 4
SELECT * FROM properties as a LEFT JOIN reservations as b ON b.room_id = a.room_id WHERE a.client = 7 AND b.start >= 2016-03-01 14:00:00 AND b.end <= 2016-03-31 11:00:00
Filename: controllers/Transactions.php
Line Number: 741
SQL:
$sql = "SELECT *
FROM properties as a
LEFT JOIN reservations as b ON b.room_id = a.room_id
WHERE a.client = $client AND b.start >= $start AND b.end <= $end";
$query = $this->db->query($sql);
日期时间是$ start和$ end ..我做错了什么?感谢
答案 0 :(得分:3)
您需要为start
和end
日期列添加引号,不能使用不带引号的日期列:
b.start >= 2016-03-01 14:00:00 AND b.end <= 2016-03-31 11:00:00
这应该是:
b.start >= '2016-03-01 14:00:00' AND b.end <= '2016-03-31 11:00:00'
修改后的查询:
SELECT *
FROM properties AS a
LEFT JOIN reservations AS b ON b.room_id = a.room_id
WHERE a.client = '$CLIENT' AND b.start >= '$START' AND b.end <= '$END'