Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


Approved MyBB - Find Users with 0 Posts filter_list
Author
Message
MyBB - Find Users with 0 Posts #1
Property of Sapientia from Discussion Zone.

Hey guys! I made a little script that will pull right from the database, and tell you how many users on your forum have no posts(0) which will let you know if your forum is inactive or active!

For our first step, we are going to create a configuration file with the database details in it for our PDO statement. Make a file called DatabaseConfig.php, and here is what I use:

Code:
<?php
$user = "Database User";
$pass = "Database Password";
$details = "mysql:dbname=Database Name;host=localhost";
$dbh = new PDO($details, $user, $pass);
?>

This will configure our database details so that we can call them from the PDO statements. Next create a page called 'PostCount.php' and lets go step by step with this.

First, what we are going to do is put down our basic opening and closing tags, and then require the config file like so:

Code:
<?php
require('DatabaseConfig.php');



?>

Next, we are going to get the total number of users on your forum, then get the number of users with 0 posts using two simple queries like so.

Code:
<?php
require('DatabaseConfig.php');

$GetCountQuery = $dbh->prepare("SELECT * FROM `mybb_users` WHERE `postnum` = 0");
$GetCountQuery->execute();
$PostCountResult = $GetCountQuery->rowCount();

$GetTotalUserQuery = $dbh->prepare("SELECT * FROM `mybb_users`");
$GetTotalUserQuery->execute();
$TheTotalUsers = $GetTotalQuery->rowCount();
$Result = $TheTotalUsers - $PostCountResult;
?>

Next, lets echo the statements telling us how many users we have, and how many have 0 posts, and how many active users we have like this:

Code:
echo "<h1>There are: " . $PostCountResult . " users with only 0 posts.</h1>"
echo "<h3>There are currently: " . $TheTotalUsers . " users signed up. Subtract the " . $PostCountResult . " with 0 posts, and that would equal " . $Result . " users that have more then 0 posts.</h3>";

Here is the whole code, and what the web page should look like!

Code:
<?php
require('DatabaseConfig.php');

$GetCountQuery = $dbh->prepare("SELECT * FROM `mybb_users` WHERE `postnum` = 0");
$GetCountQuery->execute();
$PostCountResult = $GetCountQuery->rowCount();

$GetTotalUserQuery = $dbh->prepare("SELECT * FROM `mybb_users`");
$GetTotalUserQuery->execute();
$TheTotalUsers = $GetTotalQuery->rowCount();
$Result = $TheTotalUsers - $PostCountResult;

echo "<h1>There are: " . $PostCountResult . " users with only 0 posts.</h1>"
echo "<h3>There are currently: " . $TheTotalUsers . " users signed up. Subtract the " . $PostCountResult . " with 0 posts, and that would equal " . $Result . " users that have more then 0 posts.</h3>";
?>

Spoiler:
[Image: fvry.png]
[Image: GiXvY27.png]

Reply

RE: MyBB - Find Users with 0 Posts #2
wow nice Sap. This should be pretty useful for myBB forum owners!
[Image: xlbdwZT.png]

Reply

RE: MyBB - Find Users with 0 Posts #3
I used it with Code Community when I wanted to see the inactive users.
[Image: GiXvY27.png]

Reply

RE: MyBB - Find Users with 0 Posts #4
(08-24-2013, 05:05 AM)Sapientia Wrote: I used it with Code Community when I wanted to see the inactive users.

Oh okay cool. Didn't ever know you did.
[Image: xlbdwZT.png]

Reply

RE: MyBB - Find Users with 0 Posts #5
Good stuff mate. I'm assuming this is what user pruning is based on.

Reply

RE: MyBB - Find Users with 0 Posts #6
Maybe something like this, but a lot more advanced.

I may make a tutorial on how to do that with a custom script :3
[Image: GiXvY27.png]

Reply

RE: MyBB - Find Users with 0 Posts #7
Nice! This will be useful for many mybb forum owners. Whether the forum is big or small.

Reply

RE: MyBB - Find Users with 0 Posts #8
Nice shit bro hoe Wink
lol but nice very very nice Tongue

Reply

RE: MyBB - Find Users with 0 Posts #9
Nice post but..

Code:
SELECT * FROM `mybb_users` WHERE `postnum` = 0

Code:
SELECT username FROM `mybb_users` WHERE `postnum` = 0

In SQL via PHPMyAdmin. Tongue

Reply

RE: MyBB - Find Users with 0 Posts #10
I know you can do that, but this will show the total number of users, the total number of inactive, and active users on a page with text.
[Image: GiXvY27.png]

Reply







Users browsing this thread: 1 Guest(s)