Solarpitch Posted June 17, 2008 Share Posted June 17, 2008 Hey, I'm current building a complex (complex in my terms) teetime reservation system for a golf club but I am having trouble trying to layout the code to match the below example. This code takes a date from the user and returns all avaliable teetimes on that date. It basically just returns all the times with intervals of 10 min that do not have a booking assigned to it. <?php function check_teetimes($teedate) { dbconnect(); if($membertype == "visitor") { $sql = "select * from time_sheet where realdate= '".$teedate."' OR type = 'members only'"; $page_direct = "teetime_4.php"; } else { $sql = "select * from time_sheet where realdate= '".$teedate."'"; $page_direct = "teetime_3.php"; } $myinfo = array(); //$row2 = array(); $result = mysql_query($sql) or die(mysql_error()); while(($row = mysql_fetch_row($result)) != false) { // The below bit just returns how many slots are available for each time set $slot1 = $row[3]; $slot2 = $row[5]; $slot3 = $row[7]; $slot4 = $row[9]; $avail_slots = 0; if($slot1 == "") {$avail_slots ++;} if($slot2 == "") {$avail_slots ++;} if($slot3 == "") {$avail_slots ++;} if($slot4 == "") {$avail_slots ++;} $avail_slots; if($players > $avail_slots) { $myinfo[1] = $row[1]; $exclude[] = "0".$myinfo[1]." am"; $exclude[] = "0".$myinfo[1]." pm"; $exclude[] = $myinfo[1]." am"; $exclude[] = $myinfo[1]." pm"; } } $initial_start = start_time(); foreach ($initial_start as $e) { $starting = $e[22]; } $start = "7:00"; $finish = "11:50"; $st = strtotime(date('Y-m-d') . $start); $en = strtotime(date('Y-m-d') . $finish); $int = 10 * 60; $myinfo[0] = "<select name=\"time\" id='listboxes' onchange='window.location.href=this.options[this.selectedIndex].value' style='width:200px;' size='10'>"; for ($i = $st; $i <= $en; $i += $int) { $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] .= "<option value=\"http://www.mysite.ie/booking/".$page_direct."?time=".$time_2."</option>"; } } $myinfo[0] .= "</select>"; return $myinfo; } <? This code will return the results like example 1 ... I want to structure it like example 2 but not sure how to do it. So it will be displayed a row by row basis. Row 1 will display all the 7:00 - 7:50 times, row 2 8:00 - 8:50 etc example1 example2 Link to comment https://forums.phpfreaks.com/topic/110617-structuring-a-result-set/ Share on other sites More sharing options...
rhodesa Posted June 17, 2008 Share Posted June 17, 2008 try something like: $myinfo[0] = "<table><tr>"; $last = 0; for ($i = $st; $i <= $en; $i += $int) { $hour = date('G',$i); //24 hour format if($last && $last != $hour){ //new hour $myinfo[0] .= "</tr><tr>"; $last = $hour; } $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>{$time}</td>"; } } $myinfo[0] .= "</tr></table>"; edit: really you should do this with floating LI tags instead of tables...but figured i would keep it simple Link to comment https://forums.phpfreaks.com/topic/110617-structuring-a-result-set/#findComment-567505 Share on other sites More sharing options...
Solarpitch Posted June 17, 2008 Author Share Posted June 17, 2008 Hey, yeah thats almost it I think except it just prints across the screen from left to right. Ideally what I'd like to happen is have the results break to a new line after each hour just like in my example. I am not sure how I can do that. Suppose a <br/> after each hour but not sure how to tell the code this Link to comment https://forums.phpfreaks.com/topic/110617-structuring-a-result-set/#findComment-567510 Share on other sites More sharing options...
Solarpitch Posted June 18, 2008 Author Share Posted June 18, 2008 Actually... all I would need to do to get the break after each hour is limit the columns to 6 which will cover all the times for that hour. eg: 7:00, 7:10, 7:20, 7:30, 7:40, 7:50 ... then "<br .>" after this to next line 8:00, 8:10, etc... Does anyone know how I can do this in the above code that rhodesa supplied? Thanks Link to comment https://forums.phpfreaks.com/topic/110617-structuring-a-result-set/#findComment-568028 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.