I’m trying to build a table that is 5×6 dynamically using PHP. Right now I’m getting my table to be 1×30. I’m probably missing an if statement or something but just can’t figure it out. A little help would be great.
$data = mysql_query("SELECT * FROM product")
or die(mysql_error());
$info = mysql_fetch_array( $data );
print "<table border cellpadding='0' cellspacing='0'>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr><td>".$info['name'] . " <br /><img src=".$info['pictureURL'] . " /></td></tr>";
}
print "</table>";
Here is a Demo of what it looks like http://nova.it.rit.edu/~mpb8676/FinalProject/compare.php
You are printing a new row for each record with this line:
If you want a 5×6 table, then you’ll have to add in a column counter:
There are definitely more efficient ways to go about this, but I tried to keep your code in tact so you’d better understand what your issue was.