MyBB Community Forums

Full Version: Get thread count for one forum to put on index
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, how would I go about pulling the thread count (the one that shows in the forum bit) for one specific forum so that I can put it in another location in my index template? I assume I would need to add a bit of code to my index.php file but I have no idea what I need.

Thanks! Smile
Forum bit stats I believe the variable can't be move able I have tried this before didn't work.
Where are you trying to move it to?
(01-18-2017, 08:13 AM)Dead-i Wrote: [ -> ]Forum bit stats I believe the variable can't be move able I have tried this before didn't work.
Where are you trying to move it to?

I have one forum section that is used for reviews that isn't visible on the index, and I'd like to put in my sidebar something like, "We currently have xx reviews." under the list of latest ones.

I did actually manage to figure out something that works;

// Gather Review forum stats
$where = 'fid=6';
$query = $db->simple_select('threads', 'COUNT(tid) as threads', $where);
$review_threads = (int)$db->fetch_field($query, 'threads');

I'm not sure how efficient it is though, as now I've got that I have plans to  use it for a couple of other sections, but if it's doing a query for each one, I'd prefer to someshow make it so that it's just one for all, rather than something like this;

// Gather Review forum stats
$where = 'fid=6';
$query = $db->simple_select('threads', 'COUNT(tid) as threads', $where);
$review_threads = (int)$db->fetch_field($query, 'threads');

// Gather more forum stats
$where = 'fid=7';
$query = $db->simple_select('threads', 'COUNT(tid) as threads', $where);
$more_threads = (int)$db->fetch_field($query, 'threads'); 

// Gather even more forum stats
$where = 'fid=8';
$query = $db->simple_select('threads', 'COUNT(tid) as threads', $where);
$evenmore_threads = (int)$db->fetch_field($query, 'threads');

I'm not knowledgeable about this at all, but I imagine there's a way to do it all with just one query.