Hello: I am trying to create an appointment table and am having problems. I have a loading facility that I need to create an appointment book for. The theory is simple, but where I am having problems is creating a loop for adding to the table. Basically I need a to create a form where I enter the start date, start time along with end date and end time. Let's say the facility loads every day and has hourly appointments starting at 0700 hrs and ends at 1800 hrs. I would like to enter the start date, let's say April 01, 2011 and end date of September 1, 2011. Loop and create records of each date with the hour. Can anyone help me with this please. I have included a sample of the output in my mysql table: tblName02 04/01/2011 07:00:00 04/01/2011 08:00:00 04/01/2011 09:00:00 04/01/2011 10:00:00 04/01/2011 11:00:00 04/01/2011 12:00:00 04/01/2011 13:00:00 04/01/2011 14:00:00 04/01/2011 15:00:00 04/01/2011 16:00:00 04/01/2011 17:00:00 04/01/2011 18:00:00 04/02/2011 07:00:00 04/02/2011 08:00:00 ...
you can simple process a php loop that adds to a timestamp and then places this time in the table then you need to use the php date function after leaving the timestamp to get the data to display in date format. You other option would be to setup a cron job to process your action rather than create a table to reference for each operating hour
That is over complicated, I have done exactly this when creating a driving school booking system. The date part is easy, but the time is slightly harder to increment, however in increments of an hour it is easier. I basically defined a START_TIME and END_TIME for each day. Which I then $start_time = split(START_TIME, ':'). I personally decided it would be more flexible if I then converted every time into minutes by doing ($start_time[0] * 60) + $start_time[1]; You can then incremement this in a loop by 60 and then convert back to a valid time. $new_hour = floor($i/60); $new_minute = $i%($new_hour*15); if($new_minute == 0) { $new_minute = '00'; } Here the method I used to do this, there is some unnecessary stuff in there, but just ignore it. function renderDayView($start, $end, $block_size) { $day = (int)$_REQUEST['day']; $month = (int)$_REQUEST['month']; $year = (int)$_REQUEST['year']; $start_time = explode(':', $start); $start_hours_to_min = ($start_time[0] * 60) + $start_time[1]; $end_time = explode(':', $end); $end_hours_to_min = ($end_time[0] * 60) + $end_time[1]; $query = 'SELECT * FROM lessons WHERE day = '.$day.' AND month = '.$month.' AND year = '.$year; $result = mysql_query($query); echo '<div class="lesson-holder">'; echo '<table class="day-view-table" border="1">'; for($i = $start_hours_to_min; $i <= $end_hours_to_min; $i = $i + $block_size) { echo '<tr>'; $new_hour = floor($i/60); $new_minute = $i%($new_hour*15); if($new_minute == 0) { $new_minute = '00'; } echo '<td width="60">'.$new_hour.':'.$new_minute.'</td><td> </td>'; echo '</tr>'; } echo '</table>'; while($row = mysql_fetch_array($result)) { $lesson_start_time = $row['start_time']; $lesson_start_time = explode(':', $lesson_start_time); $lesson_start_hours_to_min = ($lesson_start_time[0] * 60) + $lesson_start_time[1]; $lesson_top = ($lesson_start_hours_to_min - $start_hours_to_min) * 1.66666666667; $duration = $row['duration']; $lesson_duration = ($duration * 60) * 1.666666666667; $lesson_end_hours_to_min = ($duration * 60) + $lesson_start_hours_to_min; $end_time = $lesson_end_hours_to_min; $end_hour = floor($end_time/60); if($end_hour < 10) { $end_hour = '0'.$end_hour; } $end_minute = $end_time % 60; if($end_minute == 0) { $end_minute = $end_minute.'0'; } $display_end_time = $end_hour.':'.$end_minute; if($row['type'] == 'automatic') { $background_color = '#009ACD'; } else { $background_color = '#c30000'; } $student_query = mysql_query("SELECT * FROM students WHERE id = ".$row['student_id']); $student_result = mysql_fetch_array($student_query); $notes_limit = 70; $notes_length = strlen($row['notes']); if($notes_length >= $notes_limit) { $notes = substr($row['notes'],0,$notes_limit); $notes .= '... (<a href="lesson.php?id='.$row['id'].'">view all</a>)'; } else { $notes = $row['notes']; } echo '<div class="lesson-box" style="height:'.$lesson_duration.'px; top:'.$lesson_top.'px; background: '.$background_color.'">'; echo '<table> <tr> <td width="100"><strong>Start Time:</strong></td> <td>'.$row['start_time'].'</td> </tr> <tr> <td><strong>End Time:</strong></td> <td>'.$display_end_time.'</td> </tr> <tr> <td><strong>Duration:</strong></td> <td>'.$row['duration'].' Hours</td> </tr> <tr> <td><strong>Student Name:</strong></td> <td><a href="student.php?id='.$row["student_id"].'">'.$student_result['name'].'</a></td> </tr> </table>'; echo '<div class="lesson-options"> <a href="lesson.php?id='.$row["id"].'"><img src="images/view.png"></a> | <a href="edit-lessons.php?id='.$row["id"].'"><img src="images/edit.png"></a> | <a href="phpscripts/delete.php?type=lesson&id='.$row['id'].'&return='.urlencode($_SERVER['REQUEST_URI']).'" onclick="return confirm(\'Are You Sure?\');"><img src="images/delete.png"></a> </div>'; echo '</div>'; } echo '</div>'; } PHP:
i am satisfied with lukefowell89's code its working just need little changes in it but thanks for sharing it