Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to hide table rows when there are no lessons for that hour PHP
    primarykey
    data
    text
    <p>Im making a website for a gym in wordpress, and they wanted a timetable plugin where they can add their lessons and times.</p> <p>I got the timetable working, it displays the right lessons on the right day and time, however they also had another requirement, when there are no lessons for that hour, they do not want to display the table rows for that hour. Here's an example :</p> <pre><code> Monday | Tuesday | etc 9.00 9.15 Fitness 9.30 9.45 10.00 10.15 10.45 11.00 11.15 Another lesson </code></pre> <p>In this example, there are no lessons when its between 10.00 and 11.00 . So i only want to display 9.00 to 9.45 , hide all rows with the hour 10, and start again on 11.00 so it would look like :</p> <pre><code> Monday | Tuesday | etc 9.00 9.15 Fitness 9.30 9.45 11.00 11.15 Another lesson </code></pre> <p>However i have no idea on how to do this, i have written a piece of code that collects the data for the timetable, and a piece of code that generates the table. Here's the code that generates the table:</p> <pre><code> $table = '&lt;table&gt;'; $table .= '&lt;thead&gt;'; $table .= '&lt;tr&gt;'; $table .= '&lt;th&gt;&lt;/th&gt;'; foreach($this-&gt;arDays as $day =&gt; $id){ $table .= '&lt;th&gt;'.$day.'&lt;/th&gt;'; // Display the days on top of the table. } $table .= '&lt;/tr&gt;'; $table .= '&lt;/thead&gt;'; $table .= '&lt;tbody&gt;'; foreach($arData['times'] as $time){ // I think here should be a check if we have to display the table rows, // how ?? // Make a column with all the times $table .= '&lt;tr&gt;'; $table .= '&lt;td&gt;'.date('H:i',$time).'&lt;/td&gt;'; foreach($this-&gt;arDays as $day =&gt; $id){ // Then foreach time, foreach day check if there are lessons $table .= '&lt;td&gt;'; // There is a lesson, display it in the timetable if(!empty($arData[$day][$time])){ $arTimetable = $arData[$day][$time]; foreach($arTimetable as $oTimetable){ $table .= $oTimetable-&gt;oLesson-&gt;name; } } $table .= '&lt;/td&gt;'; } $table .= '&lt;/tr&gt;'; } $table .= '&lt;/tbody&gt;'; $table .= '&lt;/table&gt;'; echo $table; </code></pre> <p>Ive added a comment on the place where i think i should add a check that checks if we have to display the table row. </p> <p>I hope someone could help me out!</p> <p>Thanks!!</p> <p>Edit:</p> <p>This is how my data array looks for each day :</p> <pre><code>Array ( [monday] =&gt; Array ( [1382086800] =&gt; Array ( ) [1382087700] =&gt; Array ( ) [1382088600] =&gt; Array ( Lesson Object ) </code></pre> <p>Every day in the array contains all times for that day, (12 hours / 15 minutes)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload