here is the code
$sql = "SELECT * FROM $table ";
foreach ($db->query($sql) as $row) {
echo "<tr>"."
";
echo '<td>'. $row[CODE].'</td>';
echo '<td>'. $row[FIRME_CODE].'</td>';
echo '<td>'. $row[NOM_LEGAL].'</td>';
echo '<td>'. $row[NO_CIVIQUE].'</td>';
echo '<td>'. $row[NOM_RUE].'</td>';
.... and so on ...
echo "</tr>"."
";
}
the question, how it's possible to output all the value found from the query into a table WITHOUT having to tell each array table value individually...
it does not make sens... so there must be a way to do it, fast...
--
after changing it to this.. it output the word : Array in each table cell
<td> Array </td>... not good !
So the question is... what is the error in this code ?
$sql = "SELECT * FROM $table ";
$rows = $db->query($sql);
echo '<tr>';
foreach ($rows as $key => $value) {
echo '<td>', $key, '</td>';
}
echo '</tr>';
echo '<tr>';
foreach ($row as $key => $value) {
echo '<td>', htmlspecialchars($value), '</td>';
}
echo '</tr>';
Note that I've added htmlspecialchars()
which will escape your arbitrary data for use in HTML, generating valid HTML and preventing against potential XSS attacks (depending on where that data comes from).
put the query result in an array
and then foreach the array
$sql = "SELECT * FROM $table ";
$rows = $db->query($sql);
foreach ($rows as $row) {
echo '<td>'.implode('</td><td>',$row).'</td>';
}