Sinisterly
Approved MyBB - Find Users with 0 Posts - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Design (https://sinister.ly/Forum-Design)
+--- Forum: Web Design (https://sinister.ly/Forum-Web-Design)
+--- Thread: Approved MyBB - Find Users with 0 Posts (/Thread-Approved-MyBB-Find-Users-with-0-Posts)



MyBB - Find Users with 0 Posts - Sapientia - 08-24-2013

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]



RE: MyBB - Find Users with 0 Posts - Blue - 08-24-2013

wow nice Sap. This should be pretty useful for myBB forum owners!


RE: MyBB - Find Users with 0 Posts - Sapientia - 08-24-2013

I used it with Code Community when I wanted to see the inactive users.


RE: MyBB - Find Users with 0 Posts - Blue - 08-24-2013

(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.


RE: MyBB - Find Users with 0 Posts - Harvey - 08-24-2013

Good stuff mate. I'm assuming this is what user pruning is based on.


RE: MyBB - Find Users with 0 Posts - Sapientia - 08-24-2013

Maybe something like this, but a lot more advanced.

I may make a tutorial on how to do that with a custom script :3


RE: MyBB - Find Users with 0 Posts - Eclipse - 08-24-2013

Nice! This will be useful for many mybb forum owners. Whether the forum is big or small.


RE: MyBB - Find Users with 0 Posts - Cyan - 08-24-2013

Nice shit bro hoe Wink
lol but nice very very nice Tongue


RE: MyBB - Find Users with 0 Posts - Banadmin - 08-24-2013

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


RE: MyBB - Find Users with 0 Posts - Sapientia - 08-24-2013

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.