title: PHP HTML dynamically create table for time class schedule
body: <p><a href="https://i.stack.imgur.com/kpMmD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kpMmD.png" alt="enter image description here"></a>im trying to create a class scheduling table, i want to plot the schedules from may result set to create a tabular representation. </p>
  
  <p>i have a fixed header or days MONDAY-SATURDAY on top and 7:00 AM-9:00 pm on the left side of the table.</p>
  
  <pre><code>$scheduledet = json_decode(json_encode($data['scheduledet']), true);
  print_r($scheduledet);
  $week_days = array('M','T','W','TH','F','S');
  $range=range(strtotime("07:00"),strtotime("22:00"),30*60);
  $rowspan = 0;
  $rangetime = [];
  foreach($range as $time){
      $rangetime[] = date("H:i",$time);
  }
  foreach($week_days as $key =&gt; $wday){
      $schedfortheday = array_filter($scheduledet, function ($item) use ($wday) {
          if ($item['day'] == $wday) {
              return true;
          }
          return false;
      });
  
      foreach ($schedfortheday as $key =&gt; $value) {
          $rowspan = 0;
          $count = 1;
          foreach ($rangetime as $k =&gt; $v) {
  
              if(strtotime($v) &gt;= strtotime($value['fromtime']) &amp;&amp; strtotime($v) &lt;= strtotime($value['totime'])){
                  $rowspan ++;
              }
          }
      }
  }
  
  
  
  &lt;table border="2" style= "width:100%; margin: 0 auto;" cellpadding="0" cellspacing="0"&gt;
      &lt;tr&gt;
          &lt;th scope="col"&gt;&amp;nbsp;&lt;/th&gt;
          &lt;th scope="col"&gt;Monday&lt;/th&gt;
          &lt;th scope="col"&gt;Tuesday&lt;/th&gt;
          &lt;th scope="col"&gt;Wednesday&lt;/th&gt;
          &lt;th scope="col"&gt;Thursday&lt;/th&gt;
          &lt;th scope="col"&gt;Friday&lt;/th&gt;
          &lt;th scope="col"&gt;Saturday&lt;/th&gt;
      &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td&gt;7:00 AM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;7:30 AM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;8:00 AM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;8:30 AM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;9:00 AM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;9:30 AM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;10:00 AM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;10:30 AM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;11:00 AM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;11:30 AM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;12:00 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;12:30 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;1:00 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;1:30 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;2:00 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;2:30 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;3:00 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;3:30 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;4:00 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;4:30 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;5:00 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;5:30 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;6:00 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;6:30 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;7:00 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;7:30 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;8:00 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;8:30 PM&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;9:00 PM&lt;/td&gt;
      &lt;/tr&gt;
  
  &lt;/table&gt;
  Array(Array
      (
          'id' =&gt; '4545',
          'classid' =&gt; '1842',
          'fromtime' =&gt; '09:30:00',
          'totime' =&gt; '11:30:00',
          'day' =&gt; 'M',
          'room' =&gt; 'B01',
          'code' =&gt; 'BCS 1',
          'subdesc' =&gt; 'IT APPLICATION TOOLS IN BUSINESS',
          'units' =&gt; '3'
      ), Array(
          'id' =&gt; '4460',
          'classid' =&gt; '1596',
          'fromtime' =&gt; '10:30:00',
          'totime' =&gt; '11:30:00',
          'day' =&gt; 'M',
          'room' =&gt; '122A',
          'code' =&gt; 'PS 101',
          'subdesc' =&gt; 'FUNDAMENTALS OF POLITICAL SCIENCE',
          'units' =&gt; '3'
      ),Array
      (
          'id' =&gt; '4463',
          'classid' =&gt; '1598',
          'fromtime' =&gt; '13:00:00',
          'totime' =&gt; '14:00:00',
          'day' =&gt; 'M',
          'room' =&gt; 'TBA',
          'code' =&gt; 'PSOE 1',
          'subdesc' =&gt; 'PHILIPPINE POLITICAL THOUGHT',
          'units' =&gt; '3'
      ),Array(
          'id' =&gt; '3881',
          'classid' =&gt; '1597',
          'fromtime' =&gt; '14:00:00',
          'totime' =&gt; '15:00:00',
          'day' =&gt; 'M',
          'room' =&gt; 'TBA',
          'code' =&gt; 'PS 102',
          'subdesc' =&gt; 'INTRODUCTION TO PHILIPPINE POLITICS AND GOVERNANCE',
          'units' =&gt; '3'
      ),Array(
          'id' =&gt; '4540',
          'classid' =&gt; '1609',
          'fromtime' =&gt; '16:00:00',
          'totime' =&gt; '17:00:00',
          'day' =&gt; 'M',
          'room' =&gt; '205',
          'code' =&gt; 'CFE 3',
          'subdesc' =&gt; 'CATHOLIC FOUNDATION OF MISSION',
          'units' =&gt; '3'
      ))
  </code></pre>
  
  <p>this is my schedule array from my result set, if there are conflict schedule it will ovelap each rowspan and display the information of conflict schedule. i cannot plot the result set in the table. any help will be appreciated thanks in advance</p>
  
  <p>it allows schedule overlap and it will still be displayed in the table as merged table cells. the image with red cell represents 2 subjects are in conflict and with same schedule</p>
  
  <p><a href="https://i.stack.imgur.com/jUyN8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jUyN8.png" alt="enter image description here"></a></p>