1

Имеется полученный из БД массив, с неизвестным количеством строк.

При запросе:

print_r($res)

получаем:

Array ( [0] => Array ( [id] => 1 [number] => 203 [loc] => Техподдержка [fio] => Сергей Забулдыгин ) [1] => Array ( [id] => 2 [number] => 112 [loc] => Юр. Отдел [fio] => Иван Нечестный ) [2] => Array ( [id] => 3 [number] => 115 [loc] => Чертёжники [fio] => Георгий Криворуков ) )

Каким образом его развернуть в таблицу в цикле?

2 ответа 2

1
echo '<table cellpadding="5" cellspacing="0" border="1">';
  foreach ($res as $key => $value) {
echo "<tr>";
foreach ($value as $data)
    echo "<td>".$data."</td>";
echo "</tr>";
}
echo "</table>";
0

Разобрался, спасибо:

echo "<table>";
foreach ($res as $result){
        echo "<tr>";
        foreach ($result as $rValue){
                echo "<td>{$rValue}</td>";
        }
        echo "</tr>";
}
echo "</table>";

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.