0
I’m making a code where I select database information and feed an array, then I’m trying to use the contents of that array to compare with other information and process the rest of the code.
But I’m having trouble getting the data from inside the array, below my code:
<?php
$fuso = mktime(date("H")-3, date("i"), 0);
$hoje = gmdate("Y-m-d", $fuso);
//$resultado_array = array(); //sem o array
$agendamentos = $dbh->query("SELECT * FROM agenda WHERE data_agendamento='$hoje'");
while($row = $agendamentos->fetch(PDO::FETCH_ASSOC)) {
if ($row['hora_agendamento'] == "08:00:00") { //agora com $row
echo '<tr>';
echo '<td>' . $row['hora_agendamento'] . '</td>';
echo '<td>' . $row['id_paciente'] . '</td>';
echo '<td>' . $row['observacao'] . '</td>';
echo '<td>' . $row['id_agendamento'] . '</td>';
echo '<td>Editar</td>';
echo '</tr>';
}
else {
echo '<tr>';
echo '<td>08:00:00</td>';
echo '<td></td>';
echo '<td></td>';
echo '<td></td>';
echo '<td>Editar</td>';
echo '</tr>';
}
if ($row['hora_agendamento'] == "09:00:00") { //agora com $row
echo '<tr>';
echo '<td>' . $row['hora_agendamento'] . '</td>';
echo '<td>' . $row['id_paciente'] . '</td>';
echo '<td>' . $row['observacao'] . '</td>';
echo '<td>' . $row['id_agendamento'] . '</td>';
echo '<td>Editar</td>';
echo '</tr>';
}
else {
echo '<tr>';
echo '<td>09:00:00</td>';
echo '<td></td>';
echo '<td></td>';
echo '<td></td>';
echo '<td>Editar</td>';
echo '</tr>';
}
} //while agora só termina aqui
echo '</tbody></table>';
?>
In case you find inside the array the string determined there it should fill the data below, but just when starting the if already presents the error:
Notice: Undefined index: hora_agendamento in C: wamp64 www schedules index.php on line 29
Clearly because I’m not getting the data inside the array, how to proceed?
But the idea was to build a table with all the schedules that have time
08:00
? Or just the first ?– Isac
All, but you’ll only have one appointment, I won’t allow more than one appointment at the same time on the same day. In this code it is only a parameter for when find in the array this time, it fill the table with the rest of the data of that row of the array.
– Fernando Gross
tried to use var_dump to check the structure of your array?? Try running like this right after while:
var_dump($resultado_array);
and see q returns, if you still can’t find the path to get your array, edit your question with the result of var_dump.– Fernando VR
hora_agendamento
is not an index value of the array. An array’s index value is a number (0, 1, 2, 3...).– Sam