PDA

View Full Version : Small PHP Question


snowman01
02-19-2009, 06:59 PM
Is there a PHP code to use to show the number of forums hosted? Like wherever I place the code it would say something like "Currently hosting *insert number here* forums!".

BMR777
02-19-2009, 07:03 PM
Well, take a look at the script below I made a while ago. It outputs your site stats including forums, users, posts, etc. :)

<?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."";

?>

Hope it's what you need. :)

snowman01
02-19-2009, 07:06 PM
Thanks! This is what I wanted. :)