Hello
My code is a calendar and it works as follows, there is an array with some times inside:
$horarios = ["08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00"];
I then do a SELECT on the database looking for schedules and store the data inside an array through a foreach:
$stmt = $dbh->query("SELECT *, date_format(hora_agendamento, '%H%:%i') as hora_agendamento FROM agendamentos WHERE data_agendamento='$data_agendamento_convert' AND medico='$medico_completo'");
$result = $stmt->fetchAll();
After this through a for I walk inside the array and check if each time of the $ schedule array can be found inside the $ result array:
for ($i=0; $i <= (count($horarios) - 1); $i++) {
if (in_array($horarios[$i], $result[$i])) { ?>
<tr>
<td><?php echo $horarios[$i]; ?></td>
<td><?php echo $result[$i]['nome']; ?></td>
<td><?php echo $result[$i]['descricao']; ?></td>
<td>Editar</td>
</tr>
<?php } else { ?>
<tr>
<td><?php echo $horarios[$i]; ?></td>
<td></td>
<td></td>
<td>Editar</td>
</tr>
<?php } }?>
The first line found is printed correctly, then I believe that because I have 10 times in $ time and only 3 matches in $ result the code starts to return the error below:
Notice: Undefined offset: 3 in C: \ wamp64 \ www \ admin \ agenda1.php on line 91
I imagine if I improve this if I can solve the problem, but I do not know what to use to improve it, can someone give me a light?
Thank you!