spangle1187 Posted March 28, 2011 Share Posted March 28, 2011 I am trying to loop through the array that I have created to check to see if any of the dates in the array match the date I am passing (which is todays date) and then asks the user to consider making another booking. This is what I have so far but I am not sure how to finish it off: $table_id = 'booking'; $query = "SELECT * FROM booking WHERE bookingDate = 'newDate'"; $result = mysql_query($query); $loop = $end_Time - $start_Time; echo $loop; while($row = mysql_fetch_assoc($result)){ if ($startTime || $end_Time == 'booking.startTime'){ echo "choose another booking"; }{ echo "booking is ok"; } Link to comment https://forums.phpfreaks.com/topic/231953-looping-through-my-query/ Share on other sites More sharing options...
spangle1187 Posted March 28, 2011 Author Share Posted March 28, 2011 Sorry I mean times, I am wanting to look through the query to see if the time matches any held in the database not dates! Link to comment https://forums.phpfreaks.com/topic/231953-looping-through-my-query/#findComment-1193247 Share on other sites More sharing options...
Maq Posted March 28, 2011 Share Posted March 28, 2011 Why don't you just check it within the query? Link to comment https://forums.phpfreaks.com/topic/231953-looping-through-my-query/#findComment-1193249 Share on other sites More sharing options...
spangle1187 Posted March 28, 2011 Author Share Posted March 28, 2011 I had not thought of it that way round Link to comment https://forums.phpfreaks.com/topic/231953-looping-through-my-query/#findComment-1193251 Share on other sites More sharing options...
spangle1187 Posted March 28, 2011 Author Share Posted March 28, 2011 Just been looking at my code and how would that work as if the time matches then the user will have to make another booking enquiry. if I pull that as part of my query will it not just pull a blank query rather then throwing an error? Link to comment https://forums.phpfreaks.com/topic/231953-looping-through-my-query/#findComment-1193255 Share on other sites More sharing options...
Maq Posted March 28, 2011 Share Posted March 28, 2011 I had not thought of it that way round Check the time as well in your query. If you get a result back then that time is taken on that day. Link to comment https://forums.phpfreaks.com/topic/231953-looping-through-my-query/#findComment-1193260 Share on other sites More sharing options...
spangle1187 Posted March 28, 2011 Author Share Posted March 28, 2011 Your right it makes sense, thanks! Link to comment https://forums.phpfreaks.com/topic/231953-looping-through-my-query/#findComment-1193261 Share on other sites More sharing options...
spangle1187 Posted March 28, 2011 Author Share Posted March 28, 2011 I have amended the sql so that it now checks for the date as part of the query but how can I check to see if it brings back an empty result? Link to comment https://forums.phpfreaks.com/topic/231953-looping-through-my-query/#findComment-1193276 Share on other sites More sharing options...
Maq Posted March 28, 2011 Share Posted March 28, 2011 You can use - http://us3.php.net/mysql_num_rows - on the $result to check. Link to comment https://forums.phpfreaks.com/topic/231953-looping-through-my-query/#findComment-1193292 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.