Category 1 Forum 1 threads: 10 replies: 20 Forum 2 threads: 1 replies: 0 Category 2 Forum 3 threads: 14 replies 42 etc. #### @all_categories = ( { name => 'Category 1', forums => [ { name => 'Forum 1', forum_id => 1, thread_count => 10, replies => 20, }, ... ], }, ... ); #### SELECT IFNULL(COUNT(mx_replies.forum_id),0) AS reply_count, IFNULL(COUNT(mx_threads.forum_id),0) AS thread_count, IFNULL(MAX(mx_threads.id), 0) AS last_post, IFNULL(mx_threads.is_new, 0) as is_new, mx_forums.id, mx_forums.forum_name, mx_forums.forum_description FROM mx_forums LEFT JOIN mx_threads ON mx_threads.forum_id = mx_forums.id LEFT JOIN mx_replies ON mx_replies.forum_id = mx_forums.id WHERE mx_forums.category = ? GROUP BY mx_forums.id,forum_name, forum_description ORDER BY mx_forums.create_date DESC #### for ( @{ $categories } ) { $sth->execute( $_ ) or die $self->dbh->errstr; my $forums = $sth->fetchall_arrayref({}); push @all_categories, { name => $_, forums => $forums, }; } #### $tmpl->param( categories => \@all_categories ); ####
    1. : threads: last post: replies: