CodeIgniter Forums

Full Version: Outlook-esque "Week View" Calendar
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I'm attempting to create a week view calendar with 7 columns (days of the week) and 8 rows (work hours of the day 9am to 5pm). See this image for an example.

How can I best create a model that would not only populate an array with the hours in a work day (9am to 5pm) but also assign any events (from the db) to that hour, if any? Example:

  '9am' => 'some event',
  '10am' => '',
  '11am' => 'some other event'
  // all the way to 5pm

Thanks in advance!

El Forum

Hi derek,

I wrote a calendaring program many moons ago. My technique was to create an array of all the hours that I wanted to be covered in the calendar by default. Then, query the database for all events of the day and assign each event to the proper array subscript.

$cal = array(
  '9' => array(),
  '10' => array(),
  '11' => array()
  // all the way to 5pm

while ($row = mysql_fetch_assoc($result)){
    $cal[$row['starttime']][] = $row;

This allows for multiple events per time slot.