Jump to content

Help with calendar day view


Hobbyist_PHPer

Recommended Posts

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...

Link to comment
https://forums.phpfreaks.com/topic/268122-help-with-calendar-day-view/
Share on other sites

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?

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>';
    }
}

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...

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>';
    }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.