Currently I have this,
This my code
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Monday</th>
<th scope="col">Tuesday</th>
<th scope="col">Wednesday</th>
<th scope="col">Thursday</th>
<th scope="col">Friday</th>
<th scope="col">Saturday</th>
<th scope="col">Sunday</th>
</tr>
</thead>
<tbody>
<?php
if(isset($_GET['class_id'])) {
$class_id = $_GET['class_id'];
} else {
$class_id = '1'; //default class id => Yoga
}
$mQuery = "SELECT * FROM timetable where class_id = '".$class_id."'"; //code to select from database
$result = $pdo-> query($mQuery);
while($row = $result->fetch(PDO::FETCH_ASSOC)):
$timeslot = $row['timeslot'];
// pass delimiter and string to explode function
$timeslot_ar = explode(',', $timeslot);
?>
//code to display result in table
<tr class="table-active">
<?php if(date('l', strtotime($row['date'])) == 'Monday') { ?>
<td><?= date('d M', strtotime($row['date'])); ?><br/><?= implode("<br/>", $timeslot_ar); ?></td>
<?php }else { ?>
<td></td>
<?php } ?>
<?php if(date('l', strtotime($row['date'])) == 'Tuesday') { ?>
<td><?= date('d M', strtotime($row['date'])); ?><br/><?= implode("<br/>", $timeslot_ar); ?></td>
<?php }else { ?>
<td></td>
<?php } ?>
<?php if(date('l', strtotime($row['date'])) == 'Wednesday') { ?>
<td><?= date('d M', strtotime($row['date'])); ?><br/><?= implode("<br/>", $timeslot_ar); ?></td>
<?php }else { ?>
<td></td>
<?php } ?>
<?php if(date('l', strtotime($row['date'])) == 'Thursday') { ?>
<td><?= date('d M', strtotime($row['date'])); ?><br/><?= implode("<br/>", $timeslot_ar); ?></td>
<?php }else { ?>
<td></td>
<?php } ?>
<?php if(date('l', strtotime($row['date'])) == 'Friday') { ?>
<td><?= date('d M', strtotime($row['date'])); ?><br/><?= implode("<br/>", $timeslot_ar); ?></td>
<?php }else { ?>
<td></td>
<?php } ?>
<?php if(date('l', strtotime($row['date'])) == 'Saturday') { ?>
<td><?= date('d M', strtotime($row['date'])); ?><br/><?= implode("<br/>", $timeslot_ar); ?></td>
<?php }else { ?>
<td></td>
<?php } ?>
<?php if(date('l', strtotime($row['date'])) == 'Sunday') { ?>
<td><?= date('d M', strtotime($row['date'])); ?><br/><?= implode("<br/>", $timeslot_ar); ?></td>
<?php }else { ?>
<td></td>
<?php } ?>
</tr>
<?php endwhile; ?>
</tbody>
</table>
I've been trying to get my result to display in a single row for all the days and then make a new row when a day of the same name already exists. I've been trying to figure out the login behind this and after countless of stack overflow answers and youtube tutorials I got to this point. I still can't manage to get them in a single row, if anyone would be kind enough to explain the method behind this, I would really appreciate it.


forloops to cut down on the ridiculous amount of duplication in this code. An array of days would make this code collapse by a factor of seven.