To do a similar thing I use this code :
however you could try to use nested for loops
$k = 1;
echo "<TABLE BORDER BORDERCOLOR=black CELLSPACING=50 CELLPADDING=50 height=145 width=250 marginwidth=5><TR>";
while ( $row=mysql_fetch_array($result) ) {
echo "<TD bgcolor=#000066><CENTER><font face=arial size=2 color=black>";
echo " ($row[commento])";
echo "<a href=images/$row[nome]> <img src=images/$row[nome] width=134 height=100> </a></center>";
echo "</TD>";
if ( $k % 2 == 0 ) {
echo "</tr><tr>";
}
$k++;
}
echo "</tr></table>";
Brad Cerenzia wrote:
Hi,
I've been programming in PHP for about a year now, but I'm still building my logic understanding. I'm trying to find the best logic to pull items from a database and build table with n columns. I'm stuck at building the right FOR statements.
An example: I have 15 images that I want to put into a table. I have $cols=5 for the num of cols (duh!). How do I loop while/for logic to get the desired results?
Thanks for any help.
Brad