Here I stored the data in JSON format
and want to display in HTML table
. Here I have tried to fetch
but only first row
has shown, other are not showing and display some errors
like this:
Notice: Undefined index: tuesday_start in C:\xampp\htdocs\Hospital\adminpanel\show_schedule.php on line 262
Notice: Undefined index: tuesday_end in C:\xampp\htdocs\Hospital\adminpanel\show_schedule.php on line 263
Notice: Undefined index: wednesday_start in C:\xampp\htdocs\Hospital\adminpanel\show_schedule.php on line 267
Notice: Undefined index: wednesday_end in C:\xampp\htdocs\Hospital\adminpanel\show_schedule.php on line 268
and so on
Here the data is store like this:
[{"monday_start":"09.00 A.M","monday_end":"10.00 A.M"},{"tuesday_start":"10.00 A.M","tuesday_end":"11.00 A.M"},{"wednesday_start":"Select Date","wednesday_end":"Select Date"},{"thursday_start":"Select Date","thursday_end":"Select Date"},{"friday_start":"Select Date","friday_end":"Select Date"},{"saturday_start":"Select Date","saturday_end":"Select Date"},{"sunday_start":"Select Date","sunday_end":"Select Date"}]
I have tried to fetch the values like following:
<table class="table table-hover mb-0">
<thead>
<tr>
<th>Day</th>
<th>Time (From)</th>
<th>Time (To)</th>
</tr>
</thead>
<tbody>
<?php
$stmt = $conn->prepare("SELECT * FROM schedule WHERE user_id=? ");
$stmt->bind_param("s", $_GET['userid']);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows === 0) exit('No rows');
while($row = $result->fetch_assoc()) {
$times = json_decode($row['available_days'],true);
if (is_array($times) || is_object($times)) {
foreach($times as $key => $object) {
?>
<tr>
<td>Monday</td>
<td><?php echo $object['monday_start']; ?></td>
<td><?php echo $object['monday_end']; ?></td>
</tr>
<tr>
<td>TuesDay</td>
<td><?php echo $object['tuesday_start']; ?></td>
<td><?php echo $object['tuesday_end']; ?></td>
</tr>
<tr>
<td>wednesday</td>
<td><?php echo $object['wednesday_start']; ?></td>
<td><?php echo $object['wednesday_end']; ?></td>
</tr>
<tr>
<td>thursday</td>
<td><?php echo $object['thursday_start']; ?></td>
<td><?php echo $object['thursday_end']; ?></td>
</tr>
<tr>
<td>friday</td>
<td><?php echo $object['friday_start']; ?></td>
<td><?php echo $object['friday_end']; ?></td>
</tr>
<tr>
<td>saturday</td>
<td><?php echo $object['saturday_start']; ?></td>
<td><?php echo $object['saturday_end']; ?></td>
</tr>
<tr>
<td>sunday</td>
<td><?php echo $object['sunday_start']; ?></td>
<td><?php echo $object['sunday_end']; ?></td>
</tr>
<?php } } }
?>
</tbody>
</table>
Please help me...