watthehell Posted September 13, 2007 Share Posted September 13, 2007 hi, CAn anyone guide me on this: I need to check for a user reservation (time and date) and wrote this but it does not seem to work. Any help will be most welcome. <?php // here from--to is user selected time e.g 9 am to 10am if(($from <$to)) { /* checking whether the user selected time overlaps the reserved time this works fine, the problem i am having is while checking for date it does not work..I wrote those 2 queries in one */ $que1= "SELECT * FROM user_reservation WHERE (user_reserve_time_end > $from AND user_reserve_time_start < $to)"; $que_date="SELECT * FROM user_reservation WHERE user_reserve_date LIKE ".$date; $result_date = mysql_query($que_date); $result1 = mysql_query($que1); if (mysql_num_rows($result1)!=0 && mysql_num_rows($result_date)!=0) { $var1=true; $app->error_display_type=2; $app->error("This record overlaps existing time slots"); } else { // inserting value this is working } ?> The main problem is that this condition checks if the time overlaps or not but it does not check for date, it does not allow the user to save same time on different date. thnks... Quote Link to comment https://forums.phpfreaks.com/topic/69149-solved-help-on-this-query/ Share on other sites More sharing options...
Barand Posted September 13, 2007 Share Posted September 13, 2007 try <?php $que1= "SELECT * FROM user_reservation WHERE (user_reserve_time_end > '$from' AND user_reserve_time_start < '$to' AND user_reserve_date = '$date')"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/69149-solved-help-on-this-query/#findComment-347624 Share on other sites More sharing options...
watthehell Posted September 13, 2007 Author Share Posted September 13, 2007 Thanks a lot... it worked..... IT took me whole day but still i couldn't figure out what the problem was... After all Genius is Genius One more question : Why doesn't mysql compare the date like Select * from reservation where mydate=2007-9-14; And in table i have 4 records that matches this record.. Anyway thanks a lot.. Quote Link to comment https://forums.phpfreaks.com/topic/69149-solved-help-on-this-query/#findComment-347636 Share on other sites More sharing options...
Barand Posted September 13, 2007 Share Posted September 13, 2007 you need quotes round dates otherwise it reads it as 2007 minus 9 minus 14 Select * from reservation where mydate='2007-9-14'; Quote Link to comment https://forums.phpfreaks.com/topic/69149-solved-help-on-this-query/#findComment-347638 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.