MyBB Community Forums

Full Version: # of users who posted in...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello-- I thought of an idea I wanted to included within my forums and was wondering if the community could help me out. Basically all I want to know is the easiest way to count how many users posted on each board. I'm guessing I would have to connect to the post tables within my DB and count unique uid for each board? Some suggestions would be great!! thanks!
Well here is the MYSQL query you need to get you started:
mysql_query("SELECT COUNT(DISTINCT uid) FROM ".TABLE_PREFIX."posts WHERE `fid` = xxx")

Change the xxx to the fid of the forum you want to count.

This gives you the number of unique users that have posted in that forum.
Nice, I'll play around with it and let you know what happens. Thanks!
oh yeah, just to mention, that was a php query so you can only run it in the forum php files.

To run it directly into phpmyadmin use this:
SELECT COUNT(DISTINCT uid) FROM mybb_posts WHERE `fid` = xxx
Changing the "mybb_" to your prefix, and the "xxx" to the forum id again.

Toungue

I'm glad someone brought this up...it seems that a forum with over 15,000 posts in it only ever had 70 contributors...wow
Yeah, I thought it was an interesting stat to add. I'm still trying to learn how I would go about adding php into my template files. From what I've read there is no way for you to add it directly to the template file. Because of this i've come across a problem that is above my skills in my php. First I'll explain what I'm trying to use this to do. I want to include this stat along side the number of threads and posts within each forum. The problem I have is I don't know where to include this code and what to add to make it show the correct result for each forum. Get what i'm saying?
I guess I'll just have to research it a bit more. If anyone can push me in the right direction I would be very grateful. Thanks in advance!!!
You can put php variables and array items into the templates, just not any commands.

So if you put the commands in the php files, and set the variables in the files, you can use the variables in the templates.
So you suggest that I place code for EACH board over and over again; but assign them to diff variables and then include it in the template file? If so... where do I add the code... what file and what placement? and what would the example look like?

$blah = mysql query; ?
Anyone?
Quote:...to know is the easiest way to count how many users posted on each board

You mean on each forum right?

DrPoodle Wrote:
SELECT COUNT(DISTINCT uid) FROM mybb_posts WHERE `fid` = xxx
Changing the "mybb_" to your prefix, and the "xxx" to the forum id again.
this wont work... it will count all available UIDs

anyway open ./function_forumlist.php

find
$plugins->run_hooks("build_forumbits_forum");

below it add
global $db;
			$num_users_count = '';
			$num_users_count = $db->num_rows($db->query("SELECT uid FROM ".TABLE_PREFIX."posts WHERE fid='".$forum['fid']."' GROUP BY uid"));

In forumbit_depth2_forum template.

{$num_users_count}
You can put it next to another code or create a new column for it.. it depends on how you want to display it..
Pages: 1 2