Rusnak PHP Scripts Support Forums

Full Version: Simple Stats Page - Shows forums hosted, users, posts, etc
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hey All,

I made this a while back and thought I would share. It's a stats page that shows how many forums, users and posts your service has. Hope it helps. Smile

PHP Code:
<?php
include("create/mconfig.php");

//Connect to database...
$conn mysql_connect($dbhost$dbuser$dbpass) or die ("Cannot Authenticate to Database");
mysql_select_db($dbname);

//Loop through and get stats...

$posts 0;
$users 0;


$query "SELECT * FROM hosted_forums";
$result mysql_query($query);
$num mysql_numrows($result);

//Loop out code
$i=0;
while (
$i $num) {

//Grab the forum name
$fname=@mysql_result($result,$i,"fname");

//Loop through and see how many posts and users each forum has...

    
$query2 "SELECT * FROM ".$fname."_posts";
    
$result2 mysql_query($query2);
    
$num2 mysql_numrows($result2);

    
$posts $posts $num2;

    
$query3 "SELECT * FROM ".$fname."_users";
    
$result3 mysql_query($query3);
    
$num3 mysql_numrows($result3);

    
$users $users $num3;

$i++;
}

echo 
"<b>Site Statistics: </b><br><br>
Forums: "
.$i."<br>Users: ".$users."<br>Posts: ".$posts."";

?>

BMR777
how exactly do we install it?
Just copy the code. My code looks like this:
PHP Code:
<html>
<
head>
<
title>CreateBB Statistics</title>
</
head>
<
body>
<?
php
include("bb/create/mconfig.php");

//Connect to database...
$conn mysql_connect($dbhost$dbuser$dbpass) or die ("Cannot Authenticate to Database");
mysql_select_db($dbname);

//Loop through and get stats...

$posts 0;
$users 0;


$query "SELECT * FROM hosted_forums";
$result mysql_query($query);
$num mysql_numrows($result);

//Loop out code
$i=0;
while (
$i $num) {

//Grab the forum name
$fname=@mysql_result($result,$i,"fname");

//Loop through and see how many posts and users each forum has...

    
$query2 "SELECT * FROM ".$fname."_posts";
    
$result2 mysql_query($query2);
    
$num2 mysql_numrows($result2);

    
$posts $posts $num2;

    
$query3 "SELECT * FROM ".$fname."_users";
    
$result3 mysql_query($query3);
    
$num3 mysql_numrows($result3);

    
$users $users $num3;

$i++;
}

echo 
"<b>Site Statistics: </b><br><br>
Total Forums: "
.$i."<br>Total Users: ".$users."<br>Total Posts: ".$posts."";

?>
</body>
</html> 

Just a very simple HTML code with the PHP in it. You can see what it looks like here.
I once worked, now appears:
Code:
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/budziol/domains/mybbhost.pl/public_html/index.php on line 105

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/budziol/domains/mybbhost.pl/public_html/index.php on line 111
Site Statistics:

Forums: 70
Users: 237
Posts: 723

There is no change in the script.
What is the full contents of your file Budziol? My original doesn't go up to line 105 which is odd. Maybe you are using a different version?
Yes, but i'm add this script into index.php
Therefore, it is line 105
And I'm no change this script
(05-17-2009 04:05 PM)Budziol Wrote: [ -> ]Yes, but i'm add this script into index.php
Therefore, it is line 105
And I'm no change this script

Is your index.php already connected to a database? Did you change this line:

PHP Code:
include("create/mconfig.php"); 

to point to mconfig.php on your site? I am wondering if it works because index.php has its own database connection but there are other errors because you are using your own db connection.

Please post the full index.php file code so I can see how you integrated things.
Would be good if you could check how many posts in each forum.
Hmm, one of the boards I host has: 4,476 posts

But the stats page shows:
Posts: 4098

Any ideas as to why?
It shouldn't do, As you can see it tells you were it's selecting the information from. Have a look in the hosted_forums and look at the posts.
Pages: 1 2
Reference URL's