I have a PHP script selecting information from a MySQL database table and flowing it into a table using a while loop and then a foreach loop for each cell creating columns of information (date, image, sentence). My problem is these columns are side-by-side, running across my page and off into the distance (http://dankirchoff.com/drawingweek.php). I need a "carriage return" of some sort to keep them on the web page. I'm trying a modulus using the 'index' field as a counter, which isn't working. Any suggestions?
<?php
include ("inc_connect.php");
if ($link !== FALSE) {
$db = "dkfineart_01";
mysqli_select_db($db);
$TableName = "drawingoftheweek";
$sql = "SELECT * FROM $TableName";
if ($res = mysqli_query($link, $sql)) {
if (mysqli_num_rows($res) > 0) {
while ($drawresults = mysqli_fetch_array($res)) {
$drawing[] = $drawresults;
}
echo "<table style='margin-left:190px; width:500px;'><tr>";
foreach ($drawing as $draw) {
echo "<td style='padding:20px 20px 0 0'>" . date('m/d/Y', strtotime($draw['date'])) . "</td>";
}
echo "</tr><tr>";
foreach ($drawing as $draw) {
echo "<td style='padding:0 20px 0 0'>" . "<img src='images/" . $draw['image'] . ".jpg' width='400px'>" . "</td>";
}
echo "</tr><tr>";
foreach ($drawing as $draw) {
echo "<td width='400px' style='padding:0 20px 0 0'>" . $draw['drawingtext'] . "</td>";
}
echo "</tr>";
foreach ($drawing as $draw) {
$index = $draw['index'];
if ($index % 2 === 0) {
echo "<br />";
}
}
echo "</table>";
}
mysqli_free_result($res);
}
else {
echo "No matching records are found.";
}
}
else {
echo "Unable to select from table. " . mysqli_error($link);
}
mysqli_close($link);
?>