I want to loop through my data set. I want to have 5 rows of 8 cells. I cant seem to wrap my head around how to this. My code just repeats each item in my data set.
Do I need to do something like this $row[‘URL’][0]
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td><a href='" . $row['URL'] . "'><img src='" . $row['IMG'] . "'/></a></td>";
echo "<td><a href='" . $row['URL'] . "'><img src='" . $row['IMG'] . "'/></a></td>";
echo "<td><a href='" . $row['URL'] . "'><img src='" . $row['IMG'] . "'/></a></td>";
echo "<td><a href='" . $row['URL'] . "'><img src='" . $row['IMG'] . "'/></a></td>";
echo "<td><a href='" . $row['URL'] . "'><img src='" . $row['IMG'] . "'/></a></td>";
echo "<td><a href='" . $row['URL'] . "'><img src='" . $row['IMG'] . "'/></a></td>";
echo "<td><a href='" . $row['URL'] . "'><img src='" . $row['IMG'] . "'/></a></td>";
echo "<td><a href='" . $row['URL'] . "'><img src='" . $row['IMG'] . "'/></a></td>";
echo "</tr>";
}
echo "</table>";
First of all you should limit your result set in the sql query and switch to PDO or mysqli as the
mysql_*functions are deprecated.Then you can do something like:
You probably need to tidy this up a bit to complete the last row and avoid empty rows at the end, but this is just a general idea.