zed420 Posted August 26, 2009 Share Posted August 26, 2009 Hi All This query below works and avoids all the Overlaping BUT only for the first recored and thereafter it overlaps. Any thoughts please ??? Zed $query = "SELECT COUNT(*) AS Cnt FROM booking WHERE request_date='$request_date' AND e_time > '$s_time' AND s_time < '$e_time'"; Quote Link to comment https://forums.phpfreaks.com/topic/171925-select-query/ Share on other sites More sharing options...
ignace Posted August 26, 2009 Share Posted August 26, 2009 SELECT COUNT(*) AS Cnt FROM booking WHERE request_date='$request_date' AND e_time > '$s_time' AND s_time < '$e_time' GROUP BY Cnt Quote Link to comment https://forums.phpfreaks.com/topic/171925-select-query/#findComment-906600 Share on other sites More sharing options...
zed420 Posted August 26, 2009 Author Share Posted August 26, 2009 Thanks for your reply but I'm getting this msg, Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\calendar\booking.php on line 75 thanks Zed Quote Link to comment https://forums.phpfreaks.com/topic/171925-select-query/#findComment-906870 Share on other sites More sharing options...
ignace Posted August 26, 2009 Share Posted August 26, 2009 Thanks for your reply but I'm getting this msg, Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\calendar\booking.php on line 75 thanks Zed Try the query using a db interface like phpmyadmin or some other interface Quote Link to comment https://forums.phpfreaks.com/topic/171925-select-query/#findComment-906874 Share on other sites More sharing options...
zed420 Posted August 26, 2009 Author Share Posted August 26, 2009 Error SQL query: SELECT COUNT( * ) AS Cnt FROM booking WHERE request_date = '$request_date' AND e_time > '$s_time' AND s_time < '$e_time' GROUP BY Cnt LIMIT 0 , 30 MySQL said: #1056 - Can't group on 'Cnt' Quote Link to comment https://forums.phpfreaks.com/topic/171925-select-query/#findComment-906882 Share on other sites More sharing options...
ignace Posted August 26, 2009 Share Posted August 26, 2009 Error SQL query: SELECT COUNT( * ) AS Cnt FROM booking WHERE request_date = '$request_date' AND e_time > '$s_time' AND s_time < '$e_time' GROUP BY Cnt LIMIT 0 , 30 MySQL said: #1056 - Can't group on 'Cnt' Try GROUP BY count(*) Quote Link to comment https://forums.phpfreaks.com/topic/171925-select-query/#findComment-907030 Share on other sites More sharing options...
zed420 Posted August 26, 2009 Author Share Posted August 26, 2009 Thanks for your reply but I'm no joy. :'( :'( :'( Quote Link to comment https://forums.phpfreaks.com/topic/171925-select-query/#findComment-907079 Share on other sites More sharing options...
ignace Posted August 27, 2009 Share Posted August 27, 2009 SELECT DISTINCT COUNT( * ) AS Cnt FROM booking WHERE request_date = '$request_date' AND e_time > '$s_time' AND s_time < '$e_time' LIMIT 0 , 30 Quote Link to comment https://forums.phpfreaks.com/topic/171925-select-query/#findComment-907354 Share on other sites More sharing options...
zed420 Posted August 30, 2009 Author Share Posted August 30, 2009 Thanks for your reply but Unsuccessfull again. This is the background of it, A typical day's diary starts from 0800 till 2100, normally you would book an hr but just to test the script I booked 0800 to 2100 so that means all day has been booked NO other booking can be taken for this day if I DO NOT select the varibles 8 & 21 IT WILL book again and again . ????? why why????? How can I avoid that, s_time and e_time are numbers in database, this is the query I'm using Thanks Zed $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 { Quote Link to comment https://forums.phpfreaks.com/topic/171925-select-query/#findComment-909145 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.