Hobbyist_PHPer Posted September 7, 2012 Share Posted September 7, 2012 Hello everyone, I am trying to create a custom appointment calendar for an application that I'm working on, but I'm having trouble trying to figure out the logic involved with lining up appointments with their respective times on a day view of a calendar... So say you have a day view of a calendar, it lists the hours of the day vertically... What logic do you use to line up appointments from a database to those times in a day view? 'Cause the only way I can think of it is to evaluate each and every line to see if the appointment from the database comes before or after that particular time line... It just seems very sloppy and bloated... Quote Link to comment https://forums.phpfreaks.com/topic/268122-help-with-calendar-day-view/ Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 Wow. what? Get the list of appointments for that day, ordered by hour they start. You have to loop through something to list the hours anyway, then just check if the current hour has any appointments. Do you have any code yet? Quote Link to comment https://forums.phpfreaks.com/topic/268122-help-with-calendar-day-view/#findComment-1376056 Share on other sites More sharing options...
Hobbyist_PHPer Posted September 7, 2012 Author Share Posted September 7, 2012 No, I was still in the trying to figure out I was going to do it stage Quote Link to comment https://forums.phpfreaks.com/topic/268122-help-with-calendar-day-view/#findComment-1376060 Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 Well write some code Quote Link to comment https://forums.phpfreaks.com/topic/268122-help-with-calendar-day-view/#findComment-1376062 Share on other sites More sharing options...
The Little Guy Posted September 7, 2012 Share Posted September 7, 2012 Something like this: select * from appointments order by appointment_time Quote Link to comment https://forums.phpfreaks.com/topic/268122-help-with-calendar-day-view/#findComment-1376070 Share on other sites More sharing options...
Hobbyist_PHPer Posted September 7, 2012 Author Share Posted September 7, 2012 Well write some code Hey, so I wrote some code... Just a little hung up on something and can't find any documentation on it... How to detect if a number is a whole number or a decimal or float? The reason is I need to convert 1.5 to 1:30 or 1 to 1:00 ... Anyway, here's my code so far... $SelectedDay = date('Y-m-d H:i:s'); $BeginningDateTime = date('Y-m-d 00:00:00', strtotime($SelectedDay)); $EndingDateTime = date('Y-m-d 23:59:59', strtotime($SelectedDay)); $query = "SELECT * FROM Appointments WHERE AppointmentStartDateTime BETWEEN '$BeginningDateTime' AND '$EndingDateTime'"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { for ($i=1;$i<24.5;$i+=0.5) { echo '<tr>'; echo '<td style="background-color: #FFFFFF;"> '; if ($i>12.5){$e = $i - 12;} else {$e = $i;} echo $e. '</td>'; $theHour = date('G', strtotime($row['AppointmentStartDateTime'])); if ($theHour == $i) { echo '<td>'.$row['OrderTicketID'].'</td>'; } else { echo '<td> </td>'; } echo '</tr>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/268122-help-with-calendar-day-view/#findComment-1376081 Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 I would just run number_format on it, regardless of what format it is already in. Quote Link to comment https://forums.phpfreaks.com/topic/268122-help-with-calendar-day-view/#findComment-1376085 Share on other sites More sharing options...
Hobbyist_PHPer Posted September 7, 2012 Author Share Posted September 7, 2012 I would just run number_format on it, regardless of what format it is already in. I'm sorry for my ignorance, but I'm not really sure how that would work... before I made this reply I took a quick double take on php.net and I don't really see any way there either... Quote Link to comment https://forums.phpfreaks.com/topic/268122-help-with-calendar-day-view/#findComment-1376088 Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 How to detect if a number is a whole number or a decimal or float? Don't detect, just convert/format. Quote Link to comment https://forums.phpfreaks.com/topic/268122-help-with-calendar-day-view/#findComment-1376089 Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 <?php for ($i=0.0;$i<23.5;$i+=0.5){ $i = number_format($i, 1); echo $i.'-'; echo date("H:i", strtotime($i)).'<br>'; } ?> I posted this on your other thread but it's really for here. Quote Link to comment https://forums.phpfreaks.com/topic/268122-help-with-calendar-day-view/#findComment-1376108 Share on other sites More sharing options...
Hobbyist_PHPer Posted September 7, 2012 Author Share Posted September 7, 2012 I made a few changes, mostly to support 15 and 45 after the hour... anyway, here's the code... $SelectedDay = date('Y-m-d H:i:s'); $BeginningDateTime = date('Y-m-d 00:00:00', strtotime($SelectedDay)); $EndingDateTime = date('Y-m-d 23:59:59', strtotime($SelectedDay)); $query = "SELECT * FROM Appointments WHERE AppointmentStartDateTime BETWEEN '$BeginningDateTime' AND '$EndingDateTime'"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { for ($i=1;$i<24.5;$i+=0.25) { echo '<tr>'; echo '<td style="background-color: #FFFFFF;"> '; if ($i > 12.5){$e = $i - 12;} else {$e = $i;} $e = number_format($e, 2, '.', ' '); list($whole, $decimal) = explode('.', $e); if ($decimal == 25){$decimal = 15;} if ($decimal == 50){$decimal = 30;} if ($decimal == 75){$decimal = 45;} if ($whole == 0){$whole = 12;} if ($i < 12){$f = 'am';}else{$f = 'pm';} echo $whole.':'.$decimal.' '.$f.'</td>'; $theHour = date('g', strtotime($row['AppointmentStartDateTime'])); $theMinutes = date('i', strtotime($row['AppointmentStartDateTime'])); $amorpm = date('a', strtotime($row['AppointmentStartDateTime'])); if ($theHour == $whole && $theMinutes == $decimal && $amorpm == $f) { echo '<td>'.$row['OrderTicketID'].'</td>'; } else { echo '<td> </td>'; } echo '</tr>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/268122-help-with-calendar-day-view/#findComment-1376116 Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 I still think you need to go from 0 to 23.45, not 1-24.x You also have WAY more lines of code than you need! See my example? You need *ONE* line. Quote Link to comment https://forums.phpfreaks.com/topic/268122-help-with-calendar-day-view/#findComment-1376118 Share on other sites More sharing options...
mikosiko Posted September 7, 2012 Share Posted September 7, 2012 maybe is this what you are looking for: for ($i=0.0;$i<24;$i+=0.25){ $hour = floor($i); $min = sprintf("%02s",round(60*($i-$hour))); echo $hour . ':' . $min .'<br>'; } Quote Link to comment https://forums.phpfreaks.com/topic/268122-help-with-calendar-day-view/#findComment-1376127 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.