开发者

print forums under common category

开发者 https://www.devze.com 2023-01-08 12:24 出处:网络
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?

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 DEFA开发者_Go百科ULT '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'];

}


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";
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号