Answer the question
In order to leave comments, you need to log in
How to display a table from Mysql via json using a loop?
This code displays the table correctly, if you add a new row and reload the page, the table will also be updated and displayed with a new row.
$res2 = mysqli_query($conn, $sotr);
echo "<table class='table'><tr style='font-weight: bold;'><td>ФИО</td><td>Должность</td><td>Дата рождения</td><td>Мобильный номер</td><td>E-mail</td></tr>";
while ($rob = mysqli_fetch_row($res2)) {
echo "<tr><td>$rob[0]</td><td>$rob[1]</td><td>$rob[2]</td><td>$rob[3]</td><td>$rob[4]</td></tr>";
}
echo "</table>";
$res = mysqli_query($conn, $sotr);
while ($rob = mysqli_fetch_array($res)) {
$tor[] = "<tr><td>$rob[0]</td><td>$rob[1]</td><td>$rob[2]</td><td>$rob[3]</td><td>$rob[4]</td></tr>";
}
echo json_encode("<table class='table'><tr style='font-weight: bold;'><td>ФИО</td><td>Должность</td><td>Дата рождения</td><td>Мобильный номер</td><td>E-mail</td></tr>$tor[0]$tor[1]$tor[2]$tor[3]$tor[4]$tor[5]$tor[6]$tor[7]$tor[8]</table>");
$res = mysqli_query($conn, $sotr);
while ($rob = mysqli_fetch_array($res)) {
$tor[] = "<tr><td>$rob[0]</td><td>$rob[1]</td><td>$rob[2]</td><td>$rob[3]</td><td>$rob[4]</td></tr>";
echo json_encode("<table class='table'><tr style='font-weight: bold;'><td>ФИО</td><td>Должность</td><td>Дата рождения</td><td>Мобильный номер</td><td>E-mail</td></tr>$tor[0]$tor[1]$tor[2]$tor[3]$tor[4]$tor[5]$tor[6]$tor[7]$tor[8]</table>");
}
Answer the question
In order to leave comments, you need to log in
json_encode works outside of a while but doesn't work inside a while.
BUT, it's just not possible to do that.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question