tags:

views:

9

answers:

1

How would I do to print the forums under the common category?

Like if I have 3 forums with the same cat_id I want to print them together under the category. You understand?

Its hard to explain. Like this:

Category 1
Forum 1
Forum 2

Category 2
Forum 45
Forum 74

Not

Category 1 Forum 1
Category 1 Forum 2

CREATE TABLE `forums` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`forum_name` varchar(80) NOT NULL DEFAULT 'New forum',
`forum_desc` text,
`cat_id` int(10) unsigned NOT NULL DEFAULT '0'
 PRIMARY KEY (`id`)
)

CREATE TABLE `categories` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`cat_name` varchar(80) NOT NULL DEFAULT 'New Category'
PRIMARY KEY (`id`)
)

My english is poor im sorry

while ($row=mysql_fetch_assoc($query)) {

echo $row['cat_name'].$row['forum_name'];

}
A: 

I assume you have the working query?

 $old_cat = '';
 while ($row=mysql_fetch_assoc($query)) {
    if($row['cat_name'] != $old_cat){
        echo $row['cat_name']."<br>\n";
        $old_cat = $row['cat_name'];
    }
    echo $row['forum_name']."<br>\n";
 }
Wrikken