Creating a table with MySQL return results
Posted: Thu Sep 07, 2006 8:21 am
http://stesbox.co.uk/php/db/retrieve.php
I have managed to get PHP to create a table from some data but I can only get it to create the first row and the rest it ouputting unformatted. Any ideas on what's going wrong here?
[/url]
I have managed to get PHP to create a table from some data but I can only get it to create the first row and the rest it ouputting unformatted. Any ideas on what's going wrong here?
Code: Select all
<table border="2" bgcolor="grey">
<caption><b> People</b> </caption>
<tr>
<th bgcolor="black"><font color="white"> Key </th>
<th bgcolor="black"><font color="white"> Forname </th>
<th bgcolor="black"><font color="white"> Surname </th>
<th bgcolor="black"><font color="white"> Age </th>
<th bgcolor="black"><font color="white"> Sex </th></a>
</tr>
<?php
$i = 0;
while ($i < $num) {
$key = mysql_result($result, $i, "ref");
$first = mysql_result($result, $i, "fName");
$last = mysql_result($result, $i, "sName");
$age = mysql_result($result, $i, "age");
$sex = mysql_result($result, $i, "sex");
?>
<td bgcolor = "white"> <?php echo "$key"; ?> </td>
<td bgcolor = "white"> <?php echo "$first"; ?> </td>
<td bgcolor = "white"> <?php echo "$last"; ?> </td>
<td bgcolor = "white"> <?php echo "$age"; ?> </td>
<td bgcolor = "white"> <?php echo "$sex"; $i++ ?> </td>
</table>
</html>
<?php
}