MyBB Community Forums

Full Version: Display threads/posts
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

I'm wondering if anyone can quickly code something for me where it displays all members threads and posts in each forum. For example:

Username | Forum ID | #Posts | #Threads
Matt5 1 100 10
Matt5 2 5 1

Hope someone could do this for me, would make my life ALOT easier.

Doesnt have to look neat, just in a txt, or blank page. Only for my eyes
make sure you set the variables then upload and run
<?php

/**
 * @author goughy000
 * @copyright 2007
 * @Description List users with threads and posts counts per forum, requested @ mybb forums
 */

//Need to define a few variables.
$databaseusername = "username"; //username for mysql
$databasepassword = "password"; //password for mysql
$databaseserver = "localhost";  //mysql server
$databasename = "my_database";  //database name
$table_prefix = "mybb_";        //table prefix, usually mybb_


//connect up!
mysql_connect($databaseserver,$databaseusername,$databasepassword);
mysql_select_db($databasename);

//make a table
echo "<table style=\"width: 100%\">
	<tr>
		<td>Username</td>
		<td>Forum ID</td>
		<td>Threads</td>
		<td>Posts</td>
	</tr>
";




//select all the users

$usersresult = mysql_query("SELECT * FROM `".$table_prefix."users`");

//loop through users
while($userinfo = mysql_fetch_array($usersresult)){
	$forumsresult = mysql_query("SELECT * FROM `".$table_prefix."forums` WHERE `type`='f'");
	
	//loop through forums
	while($foruminfo = mysql_fetch_array($forumsresult)){
		//get total threads for this user in this forum
		$threadsresult = mysql_query("SELECT * FROM `".$table_prefix."threads` WHERE `fid`='".$foruminfo['fid']."' AND `uid`='".$userinfo['uid']."'");
		$threads = mysql_num_rows($threadsresult);
		
		//get total posts for this user in the forum
		$postsresult = mysql_query("SELECT * FROM `".$table_prefix."posts` WHERE `fid`='".$foruminfo['fid']."' AND `uid`='".$userinfo['uid']."'");
		$posts = mysql_num_rows($postsresult);
		
		//echo a row with details
		echo "<tr><td>".$userinfo['username']."</td><td>".$foruminfo['fid']."</td><td>".$threads."</td><td>".$posts."</td></tr>";
	}
}

//end the table
echo "</table>";

//please leave?
echo "<div style=\"width: 100$; text-align: right; font-size: x-small;\">Copyright Goughy000.com</div>";
?>
That's amazing. Life saver. Smile
Hi goughy,

I've got another quick question, as I'm baffled how to do it. Right, what I'm wanting is now to add total threads and posts per member in about 5 forums. I've modified the code a bit (Probabily poorly) but it looks like this:
[/php]
$usersresult = mysql_query("SELECT * FROM `".$table_prefix."users`");

//loop through users
while($userinfo = mysql_fetch_array($usersresult)){
    $forumsresult = mysql_query("SELECT * FROM `".$table_prefix."forums` WHERE `fid`='23' OR `fid`='7' OR `fid`='8' OR `fid`='9' OR `fid`='26' OR `fid`='27' OR `fid`='11' ORDER BY 'fid'");
    
    //loop through forums
    while($foruminfo = mysql_fetch_array($forumsresult)){
        //get total threads for this user in this forum
        $threadsresult = mysql_query("SELECT * FROM `".$table_prefix."threads` WHERE `fid`='".$foruminfo['fid']."' AND `uid`='".$userinfo['uid']."'");
        $threads = mysql_num_rows($threadsresult);
		

		
		#########################
        
        //get total posts for this user in the forum
        $postsresult = mysql_query("SELECT * FROM `".$table_prefix."posts` WHERE `fid`='".$foruminfo['fid']."' AND `uid`='".$userinfo['uid']."'");
        $posts = mysql_num_rows($postsresult);
        
        //echo a row with details
        echo "<tr><td>".$userinfo['username']."</td><td>".$foruminfo['fid']."</td><td>".$threads."</td><td>".$posts."</td></tr>";
    }
}

So, in forum id 23, 11, 8 etc., I'm wanting to add each persons POSTS then get the total for those, then get a total for each persons thread..! Example:

Username - Total Posts - Total Threads
Matt - 200 - 12
Bryan - 129 - 1


Matt
i havnt had time to test it but i think your after something like this:
<?php

/**
 * @author goughy000
 * @copyright 2007
 * @Description List users with threads and posts counts
 */

//Need to define a few variables.
$databaseusername = "username"; //username for mysql
$databasepassword = "password"; //password for mysql
$databaseserver = "localhost";  //mysql server
$databasename = "my_database";  //database name
$table_prefix = "mybb_";        //table prefix, usually mybb_


//connect up!
mysql_connect($databaseserver,$databaseusername,$databasepassword);
mysql_select_db($databasename);

//make a table
echo "<table style=\"width: 100%\">
	<tr>
		<td>Username</td>
		<td>Threads</td>
		<td>Posts</td>
	</tr>
";




//select all the users

$usersresult = mysql_query("SELECT * FROM `".$table_prefix."users`");

//loop through users
while($userinfo = mysql_fetch_array($usersresult)){


		$threadsresult = mysql_query("SELECT * FROM `".$table_prefix."threads` WHERE (`fid`='23' OR `fid`='7' OR `fid`='8' OR `fid`='9' OR `fid`='26' OR `fid`='27' OR `fid`='11') AND `uid`='".$userinfo['uid']."'");
		$threads = mysql_num_rows($threadsresult);
		
		//get total posts for this user in the forum
		$postsresult = mysql_query("SELECT * FROM `".$table_prefix."posts` WHERE (`fid`='23' OR `fid`='7' OR `fid`='8' OR `fid`='9' OR `fid`='26' OR `fid`='27' OR `fid`='11') AND `uid`='".$userinfo['uid']."'");
		$posts = mysql_num_rows($postsresult);
		
		//echo a row with details
		echo "<tr><td>".$userinfo['username']."</td><td>".$threads."</td><td>".$posts."</td></tr>";
}

//end the table
echo "</table>";

//please leave?
echo "<div style=\"width: 100$; text-align: right; font-size: x-small;\">Copyright Goughy000.com</div>"
?>