title: PHP calendar scheduler displaying event
body: <p>We are currently in the process of adding an event scheduler for our web control panel to allow users of the company to post their work events and track reports and the like.</p>
  
  <p><strong>A little background</strong></p>
  
  <p>The database with the events is structured to include the following:</p>
  
  <pre><code>cid, ceventpostedby, ceventstart, ceventend, ceventday, ceventmonth, ceventyear,
  ceventtitle, ceventdesc, cuserdomain, ceventlocation, clastupdated
  </code></pre>
  
  <p>With a typical entry looking something like the following:</p>
  
  <pre><code>1, 1, 8:30, 13:30, 30, 1, 2017, Some Event, Event Desc, example.com, Some City, 142000000
  </code></pre>
  
  <p>These events are loaded into a calendar that only users in the same domain group (and root admins) can see, to keep them separate for different web groups in the system. This is defined by the <code>cuserdomain</code> field. A typical calendar will look something like the following picture:</p>
  
  <p><a href="https://i.stack.imgur.com/bGIvf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bGIvf.png" alt="Event Scheduler - Main Page"></a></p>
  
  <p>When a user clicks on a day they are taken to a page that will show the current daily events if any are set or show a blank schedule with 7AM - 7PM on it (times are chosen as users work office hours and events shouldn't be booked later or earlier than these times). The page looks like the following when it is empty and no events are booked:</p>
  
  <p><a href="https://i.stack.imgur.com/Pyz3m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Pyz3m.png" alt="Event Scheduler - Selected Day"></a></p>
  
  <p><strong>Now some PHP..</strong></p>
  
  <p>So the event page is checking if there is an event present on that day and setting a yes or no. If it does have events, it should print them out into the right time box. If not, just show all the time slots between the set 7AM-7PM (or 12 hours). We are using the following code</p>
  
  <pre><code>for($i = 0; $i &lt; 12; $i++) {
      if($starting_time == 12) {
          // default is AM, change to pm after noon
          $time_type = "PM";
      }
      if($starting_time &gt; 12) {
          // reset the time to 1 instead of 13 for user ease
          $starting_time = "1";
      }
      if(mysqli_num_rows($schedule_events_query) &gt; 0) {
          while($event_result = mysqli_fetch_array($schedule_events_query)) {
              $time_start = $event_result['ceventstart'];
              $time_end = $event_result['ceventend'];
              $time_start = explode(":", $time_start);
              $time_end = explode(":", $time_end);
              // CODE SHOULD GO HERE TO DISPLAY THIS EVENT
          }
      } else {
          // Using custom template engine we call the empty blocks 12 times
          // since there was no event scheduled for today.
          echo $x10-&gt;template-&gt;extract("calendar_empty_schedule", $starting_time, $time_type);
      }
      $starting_time++;
  }
  </code></pre>
  
  <p><strong>And finally the problem / question</strong></p>
  
  <p>If an event is booked on that day or even multiple events, how can I print them so they fill in the blocks on their time start and stop? So far simply printing a block only prints one block per event and doesn't show the rest of the days hours. I also don't know how to go about showing the specific blocks for each event as different and then showing the rest. I'm sure it's not a difficult thing to produce but I can't seem to wrap my mind around it as I've spent so much time on this panel by myself already that I feel numb (lol). Any suggestions are welcome and help appreciated. I worked hard making this post contain as much data as possible. Here is an html snippet of a day block also for reference</p>
  
  <pre><code>            &lt;div class="schedule_item_row"&gt;
                  &lt;div class="time"&gt;
                      &lt;div class="time_smaller"&gt;
                          &lt;div class="time_smaller_item"&gt;
                              &lt;div style="padding-top: 13px;"&gt;00&lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="time_smaller_item"&gt;
                              &lt;div style="padding-top: 13px;"&gt;30&lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div style="padding-top: 32px;"&gt;8 AM&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="schedule_info"&gt;
                      &lt;div class="schedule_block"&gt;
                          &lt;div style="padding: 13px;"&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="schedule_block"&gt;
                          &lt;div style="padding: 13px;"&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="clear"&gt;&lt;/div&gt;
              &lt;/div&gt;
  </code></pre>