Basically I’ve retrieved data from mysql on 1 line and made it look like a table with borders and stuff but I’d want it to repeat for every row on the mysql table. Here’s the following code I’ve used so far:
while($info = mysql_fetch_array( $data ))
{
echo "<table width='1000' cellpadding='10' cellspacing='5' border='1'>";
echo "<tr>
<td><center><b>".$info['id']."</td></center></b>"."<td><center><b>".$info['username']."</td></center></b>"."<td><center><b>".$info['kills']."</td></center></b>"."<td><center><b>".$info['deaths']."</td></center></b>"."<td><center><b>".$info['ratio']."</td></center></b></tr>";
echo "</table>";
}
UPDATE:
echo "<table width='1000' cellpadding='10' cellspacing='5' border='1'>";
while($info = mysql_fetch_array( $data ))
{
echo "<tr>
<td><center><b>".$info['id']."</td></center></b>"."<td><center><b>".$info['username']."</td></center></b>"."<td><center><b>".$info['kills']."</td></center></b>"."<td><center><b>".$info['deaths']."</td></center></b>"."<td><center><b>".$info['ratio']."</td></center></b></tr>";
}
echo "</table>";
You want the table tage outside the loop that fetches the rows of data:
As you are new to PHP I should probably expand this out a little more:
Your code will now echo out the table opening tag:
Then go into the while loop and echo out all the rows that it finds:
Then when it exists the loop, it will output the closing tag for the table:
What you were previously doing was outputting a table for each and every row of data. For future reference, it is a good idea to look into your source code to get an understanding of what is happening.
Edit: When I was going through your code comment, I formatted it out neater to see what was going on, you might want to make your code easier to read by having the following format: