简体   繁体   中英

Trouble with mysql query in php?

$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."' "; 

I dont know where it went wrong .. i have to check roomtype,room no , on and between checkin and checkout date...

Iam getting the roomttype,roomno ,checkin,checkout values from the form ..Now i have to compare it with database.

Here

$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."' ";

you are having an invalid syntax in your where clause, as you should not check equality in the between operands. This should fix the issue:

$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."' ";

Read more about between here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM