PDA

View Full Version : How to set table cols and rows



sinox
05-24-2007, 12:10 AM
I'm trying to make a table of images that I have stored in a database. When it prints out the images they are in a straight line horizontal or vertical, is there a way I can tell the table how many cols I want and the spill over will start a new row?

Example. I want 3 cols and 3 rows

codeexploiter
05-24-2007, 04:47 AM
You can develop an HTML table based on the number of rows and columns you need and that will solve your problem

djr33
05-24-2007, 05:14 AM
<table>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6</td></tr>
<tr><td>7</td><td>8</td><td>9</td></tr>
</table>

to output that from a database, simply create a loop.
for ($i=0;$i<3;$i++) ... that will go every three times,
then you can create the rest of it.

So, something like--

echo "<table><tr>\n";
foreach ($images as $image) {
echo "<td><img src=\"$image\" alt=\"image\"></td>";
$i++;
if ($i&#37;3 == 0) {echo "</tr><tr>"; }
}
echo "</tr></table>";