2010-07-19 63 views
1

我如何打印普通類別下的論壇?普通類別下的打印論壇

就像我有3個論壇有相同的cat_id我想在類別下一起打印它們。你明白?

很難解釋。就像這樣:

1類
論壇1
論壇2

類別2
論壇45
論壇74

1類論壇1
1類論壇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`) 
) 

我的英語很差IM對不起

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

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

} 

回答

0

我假設你有工作查詢?

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