Forum Moderators: coopster

Message Too Old, No Replies

SQL result Data in mulitple rows and columns of table

data in rows and columns

         

fastfriend

8:39 am on Oct 17, 2005 (gmt 0)

10+ Year Member



Hello Friends

I am a newbie in PHP. I have been facing problem in displaying result of MySQL Fetch Query in multiple rows and columns.

I have just one item namely "categories", in which I have categories of Autos such as Toyota, Suzuki, Nissan, Hyundai, Mazda, Honda and so on.....

The problem is that I want to display 3 categories in a ROW and if categories are more than 3 than it add one row and show 4 more and so on.......

Like above I mentioned 6 Auto Companies, it should display like

Toyota Suzuki Nissan
Hyundai Mazda Honda

I have tried different loops but NO Success.

I would be thankful if someone guide me with explanation or some tutorial.

Thanks

arran

11:34 am on Oct 17, 2005 (gmt 0)

10+ Year Member



Try something like (untested):

$num_columns = 3;
print "<table><tr>";
for ($i; $i < $num_categories; $i++) {
print "<td>";
print <category $i>
print "</td>";
if ($i > 0 && ($i < $num_categories-1) && ($i % $num_columns == 0)) {
print "</tr><tr>";
}
}
print "</tr></table>";

arran.