Forum Moderators: coopster
Name Color Ranking
Bob Orange 1
Mark Red 1
John Blue 1
Bob Yellow 2
Mark Green 2
John Purple 2
Can I convert the above list to display in a table format using php like this:
Bob Mark John
1 Orange Red Blue
2 Yellow Green Purple
I'm not sure how to approach it. Any ideas?
$sql = 'SELECT * FROM `table`';
$result = mysql_query($sql) or die ("Couldn't execute query.");//initialize table
echo "<table width=\"100%\" style=\"border:1px solid #000000; font-size:x-small;\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\">";echo "<tr style=\"background-color:#802020; color:#FFFFFF;\"> <th>City</th> <th>State</th> <th>Zip</th> </tr>";
//put results into an array one row at a time
while ($row= mysql_fetch_array($result))
{
//sample array with city, state, and zip if I want to use the data for something else later
$tempzip = $row['Zip_Code'];
$tempstate = $row['State'];
$tempcity = $row['City'];
//I can still do any other work I need to do on that line here
// Print out the contents of each row into a table
echo "<tr bgcolor=\"$colour\" class=\"trhover\"><td>";
echo $row['City'];
echo "</td><td>";
echo $row['State'];
echo "</td><td>";
echo $row['Zip'];
echo "</td><td>";
}
echo "</table>";
Drunk