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





Messages In This Thread
MyBB - Find Users with 0 Posts - by Sapientia - 08-24-2013, 04:00 AM



Users browsing this thread: 2 Guest(s)