954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How can i check using AND, OR?

hi,
this is relating to a wordpress site, i have this query

$qstring="SELECT * FROM rwb_bk_schedule s INNER JOIN rwb_bk_rooms r ON s.room_id = r.room_id WHERE s.room_status=1 AND r.room_name='".$room."' AND start_date BETWEEN '".$sdate."' AND '".$edate."' OR end_date BETWEEN '".$sdate."' AND '".$edate."'";


as i given the code i use OR there between, but when i use OR this query wont return all the results which has s.room_status=1 rather return s.room_status=anything.
now can i check this ?
help much appreciated.

Virangya
Junior Poster
122 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

You have to bracket the clauses of the OR condition:

SELECT * 
FROM rwb_bk_schedule s 
INNER JOIN rwb_bk_rooms r 
ON s.room_id = r.room_id 
WHERE s.room_status=1 
AND r.room_name=$room
AND (start_date BETWEEN $sdate AND edate OR end_date BETWEEN sdate AND $edate)
smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: