Forum Moderators: coopster
<table border="1"><?php
$result = mysql_query("SELECT * FROM people");if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
exit();
}while ( $row = mysql_fetch_array($result) ) {
echo("<tr><td>" . $row["first"] . $row["last"] . "</td></tr>");
}?>
</table>
How could I get a second column automatically added when the list is larger?
$result = mysql_query("SELECT first, last FROM people");
...
while ($row = mysql_fetch_assoc($result)) {
echo "<tr><td>";
foreach($row as $value) echo $value;
echo "</td></tr>";
}
Or you can use the code based on what electricocean wrote:
while ($row = mysql_fetch_array($result)) {
echo "<tr><td>";
for($p = 0; $p < 2; $p++) echo $row[$p];
echo "</td></tr>";
}
However here you must also be concieus that you are selecting correct answers.
mysql_fetch_array gives you results that are both numbered and associated as well.
Best regards
Michal Cibor
And welcome to WebmasterWorld!