Forum Moderators: coopster
$query = "SELECT b_id, COUNT(*) AS Cnt
2.FROM booking
3.WHERE request_date='$request_date'
4.AND e_time > '$s_time'
5.AND s_time < '$e_time'
6.GROUP BY b_id";
7. $result = mysql_query($query);
8. $row = mysql_fetch_assoc($result);
9. if($row['Cnt'] > 0){
10. error_message('Sorry, this time is already booked. Please choose another');
11. } else {
SELECT b_id, COUNT(*) AS Cnt
FROM booking
WHERE request_date='$request_date' AND
(
($s_time >= s_time AND $s_time < e_time) OR
($e_time > s_time AND $e_time <= e_time)
)
GROUP BY b_id
New booking starts before e-start time, and finishes after e-start and before e-end time.
New booking starts before e-start time and finishes after e-end time.
New booking starts after e-start and before e-end time, and finishes before e-end time.
New booking starts after e-start and before e-end time, and finishes after e-end time.
If you phrase those four possibilities into your OR statement I would think you'd have it covered?