Web Site Status, integrated with blogs, forums, any database

Some of you may have noticed the stats on my home page. The stats show how many blog posts, forum posts, and forum users there are. I will show you how to use my code to do the same on your web site.

Putting stats on your web page will allow your uses see how your site is doing. It will also provide a quick tool for you to track your blog and forum is a very simplistic way.

This code will work perfectly with the default database tables of WordPress and PhpBB.

<?php
// Blog entries
$link = mysql_connect(“localhost”,”BLOGDATABASE“,”PASSWORD“);

if ($link) {
mysql_selectdb(“BLOGDATABASE“,$link);

$query  = “SELECT COUNT( post_type ) FROM wp_posts WHERE post_type = ‘post'”;
$result = mysql_query($query);

// Display records from the table
echo “<table border=’0’>”;
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo “<tr><td><strong>$row[0]</strong>&nbsp;Blog Entries and</td><td>$row[1]</td><td>$row[2]</td></tr>”;
}
echo “</table>”;
} else {
echo “Can’t connect to the database!”;
}

// FORUM Posts
$link = mysql_connect(“localhost”,”FORUM“,”PASSWORD“);

if ($link) {
mysql_selectdb(“FORUM“,$link);

// Select records from the DB
$query  = “SELECT sum( FORUM_posts ) -1 num FROM phpbb_FORUMs“;
$result = mysql_query($query);

// Display records from the table
echo “<table border=’0′>”;
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo “<tr><td><strong>$row[0]</strong>&nbsp;forum Posts with </td>”;
}
//echo “</table>”;
} else {
echo “Can’t connect to the database!”;
}

// FORUM Users
$link = mysql_connect(“localhost”,”FORUM“,”PASSWORD“);

if ($link) {
mysql_selectdb(“FORUM“,$link);

// Select records from the DB
$query  = “SELECT sum( user_allow_viewemail ) -51 num FROM phpbb_users“;
$result = mysql_query($query);

// Display records from the table
//echo “<table border=’0′>”;
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo “<td><strong>$row[0]</strong> forum Users</td><td>$row[2]</td></tr>”;
}
echo “</table>”;
} else {
echo “Can’t connect to the database!”;
}

// Create the connection and select the DB
$link = mysql_connect(“localhost”,”DATABASE“,”PASSWORD“);

if ($link) {
mysql_selectdb(“time“,$link);

// Select records from the DB
$query  = “SELECT CURRENT_TIMESTAMP;”;
$result = mysql_query($query);

// Display records from the table
echo “<table border=’0′>”;
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo “<tr><td>Date Stamp: $row[0]</td><td>$row[1]</td><td>$row[2]</td></tr>”;
}
echo “</table>”;
} else {
echo “Can’t connect to the database!”;
}

?>

Replace all the bold variables with your data for best results. Save the file as a php file and upload it to your site.

Leave a Reply

Your email address will not be published. Required fields are marked *