EllisLab text mark
Advanced Search
Calendar Multiple Events Per Day (Available)
Posted: 17 August 2011 09:40 AM
Joined: 2011-08-16
2 posts

Because yesterday i’ve search the forum and i saw many people search for a way to have multiple events per day on the codeigniter calendar. Here is the code that i made in order my calendar to have multiple events per day.

The calendar is based on the nettus tutorial if anyone interested and can be found here: .(JavaScript must be enabled to view this email address)

Step 1) make sure the nettuts way of calendar work on you.

Step 2) copy the calendar.php from system/libraries to application/libraries

Step 3) make an adjustment in the calendar.php library in line 217 and put the code below (Thanks to member zoltano):

if (isset($data[$day]))
// Cells with content
$temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_content_today'$this->temp['cal_cell_content'];
                                                if (
                                                    foreach (
$data[$day] as $key)
.= $key.'<br />';
.= str_replace('{day}'$daystr_replace('{content}'$several_events$temp));

// One event per day
.= str_replace('{day}'$daystr_replace('{content}'$data[$day]$temp));
// Cells with no content
$temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_no_content_today'$this->temp['cal_cell_no_content'];
$out .= str_replace('{day}'$day$temp);

Step 4) now on the calendar model you must make your output array. The code you must put on the get_calendar_data function of the model is shown below:

function get_calendar_data($year$month{
$this->db->query("SELECT DISTINCT DATE_FORMAT(date, '%Y-%m-%e') AS date
                                            FROM calendar
                                            WHERE date LIKE '
$year-$month%' "); //date format eliminates zeros make
                                                                           //days look 05 to 5
$cal_data = array();
                foreach (
$query->result() as $row//for every date fetch data
$a = array();
$i 0;
$query2 $this->db->query("SELECT data
                                                FROM calendar
                                                WHERE date LIKE DATE_FORMAT('
$row->date', '%Y-%m-%d') ");
//date format change back the date format
                                                            //that fetched earlier
foreach ($query2->result() as $r{
$r->data;     //make data array to put to specific date

return $cal_data;

You are done !!  grin
Result on photo here: Multiple Events Codeigniter Calendar
Good luck coding.

Posted: 21 January 2013 07:23 AM   [ # 1 ]   [ Rating: 0 ]
Joined: 2012-08-24
5 posts

and the controller?

Posted: 29 April 2014 11:27 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2014-04-29
2 posts

can you explain the last function?
why isn’t it displaying the events after loading the calendar,
the event will only show when i click the prev or next on the calendar