Solarpitch Posted June 24, 2008 Share Posted June 24, 2008 Hi, Almost finished this part of my application. If you take a look at the below image which is an example of what the following piece of code will output. It displays a list of golf teetimes from 7:00am to 12:00am with a number of available slots for that specific time. There can be a max of only 4 slots for each time. The code simply takes the 7:00am and 11:50am start and end time and calculates 10min intervals in between. (Teetime every 10 min). I am basically having trouble trying to return the available slots for each time. This example output shows how far I am getting at the min... So the only problem I have is calculating the available slots for each time from 7:00 to 11:50 and displaying them in the above section for each time slot. This is the function I have. <?php function check_teetimes($teedate); { $sql = "select * from golfpro_time_sheet where realdate= '".$teedate."'"; $myinfo = array(); $result = mysql_query($sql) or die(mysql_error()); //This is how I calculate available slots. I check 4 columns in the database, if it is empty then that slot is available to be booked so increment the availability of that time. while(($row = mysql_fetch_row($result)) != false) { $slot1 = $row[3]; $slot2 = $row[5]; $slot3 = $row[7]; $slot4 = $row[9]; $avail_slots = 0; if($slot1 == "") {$avail_slots = $avail_slots + 1;} if($slot2 == "") {$avail_slots = $avail_slots + 1;} if($slot3 == "") {$avail_slots = $avail_slots + 1;} if($slot4 == "") {$avail_slots = $avail_slots + 1;} // Set the start and finish time and calcaulate a 10 min interval $st = strtotime(date('Y-m-d') . "7:00"); $en = strtotime(date('Y-m-d') . "11:50"); $int = 10 * 60; $myinfo[0] = "<table id='table'><tr>"; $last = 07; for ($i = $st; $i <= $en; $i += $int) { $hour = date('h:i a',$i); $d1 = split(":",$hour); $breakhour = $d1[0]; // This will just tell the code to break to a new line when it see's a new hour. if($last && $last != $breakhour){ //new hour $myinfo[0] .= "</tr><tr>"; $last = $breakhour; } $time = date('h:i a',$i); $time_2 = date('G:i',$i); //if NOT in the exclude array then add a value if( !in_array($time, $exclude) ) { $myinfo[0] .= "<td id='slot_bk' ONMOUSEOVER=\"popup('$player','yellow')\"; ONMOUSEOUT='kill()'>$time<br>Slots:$t</td>"; } } } $myinfo[0] .= "</tr></table>"; return $myinfo; } } ?> Link to comment https://forums.phpfreaks.com/topic/111672-help-needed-with-small-teetime-application/ Share on other sites More sharing options...
Solarpitch Posted June 24, 2008 Author Share Posted June 24, 2008 *Bump* - Any help with this would be appreciated. I know its not the most straight forward question on the forum but I've been at it for hours. Just to Re-Cap, the system - Generates times from 7:00 to 11:50 - Needs to check the database to see if there are bookings for any of these times - If there are, calculate how many slots are available - Rest of the time slots should default to 4 as there are no booking in the database for those times. Link to comment https://forums.phpfreaks.com/topic/111672-help-needed-with-small-teetime-application/#findComment-573336 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.