Using PHP to format SQL results
Posted: Wed May 14, 2008 12:04 am
First of all, I just picked up PHP and SQL out of necessity for a new site. What I've learned so far has amazed me. I'm having a little hiccup, though. I'm using PHP to execute queries to an item database and "echo"ing the html code to set the returns in a table. The method I'm using, though, is only allowing one cell per table row. I'd like to have the items displayed two-per-row. I've tried to manipulate the code a little, but have yet to find a solution. The example code below is returning the results in a single table row. Any ideas on how to drop in a </tr><tr> after every two results?
Code: Select all
if (mysql_num_rows($result) > 0) {
echo "<table border=0 cellspacing=0 cellpadding=0 class=box_width_cont product>";
echo "<tr>";
while($row = mysql_fetch_row($result)) {
echo "<td>";
echo "<center><img height=125 width=175 src=".$row[1]."></center>";
echo "<center><font color=#855b63><b>".$row[2]."<br>".$row[3]."<br>".$row[7]." Cut<br>Size: ".$row[4]."</b><br><br></font><font color=#855b63 size=3><b>".$row[10]."</b></center></font><br>";
echo "<center><a href=items/".$row[0].".php><img src='images/button_details.gif'></a></center>";
echo "</td>";
}
echo "</tr>";
echo "</table>";
}
else {
// no
// print status message
echo "No items found!";
}