[phpBB3 - EASY] How to add forum statistics to your website!

Sub-Zero

New Arrival
Joined
Jul 7, 2010
Messages
12
Reaction score
0
FP$
6
Live Demo: http://phpbbtesting.99k.org/website.php

In this tutorial, I'm basically going to show you how to add your forum statistics to your website. And, after the tutorial is over, there is another mini-tutorial on how you can add how many views your forum has. So please, rate this tutorial and give feedback as its greatly appreciated!

Step One: After you have phpBB3 installed, or you already have an active forum - Go into your website control panel and open up your website files. Then go to the page you wish to add the statistics to. In this case, we're going to be using Index.php (remember, you can add it to any file on your website, so you don't have to use Index.php) to display the statistics. So, once you have the file opened, you can move onto the next step, which is two.

Step Two: After your file is opened, you want to find the spot where you want to add the statistics. I'm just going to be using a blank file, so I'll just only have the PHP code. So go into your website hosting panel and get the information to your database that stores the tables for the phpBB3 forums. After you have the data, put this PHP code where you want the statistics to display:

Code:
<?php

//change the details inside the quotes to your database values
$mysql_username = "your database username";
$mysql_password = "your database password";
$mysql_database = "your database name";
$mysql_host = "your database host";

//connects to the database
mysql_connect($mysql_host, $mysql_username, $mysql_password);
mysql_select_db($mysql_database);

//make sure the prefix is correct

//number of posts 
$posts_sql = mysql_query("SELECT COUNT(post_id) FROM phpbb_posts");
$posts_count = mysql_fetch_assoc($posts_sql);

//number of threads
$threads_sql = mysql_query("SELECT COUNT(topic_id) FROM phpbb_topics");
$threads_count = mysql_fetch_assoc($threads_sql);

//number of users
$users_sql = mysql_query("SELECT COUNT(user_id) FROM phpbb_users");
$users_count = mysql_fetch_assoc($users_sql);

echo "There are currently ". $users_count['COUNT(user_id)'] ." users registered on the site. They have made a total of ". $posts_count['COUNT(post_id)'] ." posts, and ". $threads_count['COUNT(topic_id)'] ." topics.";

?>

Step Three: Thats basically it. Make sure the database information is correct, and the correct prefixes are used. In that example code, phpbb_ is used. Basically, the part where it "echos" it is where the text is displayed. The example of the text output would be: There are currently 26 users registered on the site. They have a total of 106 posts, and 49 topics.

OPTIONAL - Step Four - To make it so you can store the amount of forum views your forum has, go into your FTP and edit the config.php file for phpBB3. Keep that file open, and then go back into your website hosting panel and open up phpMyAdmin. Go to the tab that says "SQL". Click on it, and paste in this code:

Code:
CREATE TABLE `views` (
  `views` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

Then run it/submit it. You should have a new table called views. Now click on the new table called views, which can be found on the very left hand side (the navigation bar with all the phpbb_ prefixes). Once you have clicked it, click on the "Insert" tab on the top navigation bar. Set the value to 0, and leave everything else the same. Click go. You have finished all the work you've had to do in the database, so you can close phpMyAdmin now! 🙂

OPTIONAL - Step Five - Go back to your config.php file for phpBB3 (in your websites FTP/File Manager) and add in this code BELOW everything else:

Code:
mysql_connect($dbhost, $dbuser, $dbpasswd);
mysql_select_db($dbname);

mysql_query("UPDATE views SET views = views +  1");

If your still not sure where your suppose to put that code, here is an example of my config.php:

Code:
<?php
// phpBB 3.0.x auto-generated configuration file
// Do not change anything in this file!
$dbms = 'mysqli';
$dbhost = 'mysql3.000webhost.com';
$dbport = '';
$dbname = '************';
$dbuser = '***************';
$dbpasswd = '****************';
$table_prefix = 'phpbb_';
$acm_type = 'file';
$load_extensions = '';

mysql_connect($dbhost, $dbuser, $dbpasswd);
mysql_select_db($dbname);

mysql_query("UPDATE views SET views = views  + 1");

@define('PHPBB_INSTALLED', true);
// @define('DEBUG', true);
// @define('DEBUG_EXTRA', true);
?>

If you want to display the views with your statistics, then update your statistics code to look somewhat like this:

Code:
<?php

//change the details inside the quotes to your database values
$mysql_username = "your database username";
$mysql_password = "your database password";
$mysql_database = "your database name";
$mysql_host = "your database host";

//connects to the database
mysql_connect($mysql_host, $mysql_username, $mysql_password);
mysql_select_db($mysql_database);

//connects to the database
mysql_connect($mysql_host, $mysql_username, $mysql_password);
mysql_select_db($mysql_database);

//make sure the prefix is correct

//number of posts 
$posts_sql = mysql_query("SELECT COUNT(post_id) FROM phpbb_posts");
$posts_count = mysql_fetch_assoc($posts_sql);

//number of threads
$threads_sql = mysql_query("SELECT COUNT(topic_id) FROM phpbb_topics");
$threads_count = mysql_fetch_assoc($threads_sql);

//number of users
$users_sql = mysql_query("SELECT COUNT(user_id) FROM phpbb_users");
$users_count = mysql_fetch_assoc($users_sql);

//forum views
$view_sql = mysql_query("SELECT views FROM views");
$views = mysql_fetch_assoc($view_sql);

echo "There are currently ". $users_count['COUNT(user_id)'] ." users registered on the site. They have made a total of ". $posts_count['COUNT(post_id)'] ." posts, and ". $threads_count['COUNT(topic_id)'] ." topics. The forum has been viewed ". $views['views'] ." times.";

?>
 
Re: [phpBB3 - EASY] How to add forum statistics to your webs

Do you have a working/live example of this, or screen shots?
 
Re: [phpBB3 - EASY] How to add forum statistics to your webs

Nice would you care to sumbit it to our phpBB knowledge base at TheHazey?
 
Re: [phpBB3 - EASY] How to add forum statistics to your webs

richazey said:
Nice would you care to sumbit it to our phpBB knowledge base at TheHazey?

Well I have to do a few changes to it. I need to make it so it only gets posts from categories that allow it.
 
Re: [phpBB3 - EASY] How to add forum statistics to your webs

That would be awesome as my site is looking for articles just like this 🙂
 
Re: [phpBB3 - EASY] How to add forum statistics to your webs

richazey said:
That would be awesome as my site is looking for articles just like this 🙂

Alright, I'm starting on making the code get the correct amount of posts and topics. 🙂
 
Back
Top Bottom