I want to put this Board Statistics on my Homepage, but how can I do that:
We currently have XXX members registered.
Please welcome our newest member, XXX
Thank you (MyBB version:1.00 Preview Release 2)
Hi,
I have made something similar to what you want. Now its not the best piece of code in the world but it gets the job done.
The code ...
<?php
include("database.php"); // database information in the form of variables
$forum['url'] = "http://www.example.com/forum/"; // the url of your forum (dont forget the trailing slash)
mysql_connect($forum['hostname'],$forum['username'],$forum['password']); // connects to the SQL server
mysql_select_db($forum['database']); // Selects the database
$query="SELECT * FROM mybb_users"; // the information is stored in this table
$users=mysql_query($query); // selects the table specifyed by the queary variable
$stats['members'] = mysql_numrows($users); // Number of rows in the users table -1 returns an accurate number of regestered users.
$stats['latest_member'] = mysql_result($users,$stats['members'] - 1,"username"); // Returns the latest user to regester.
$stats['id_member'] = mysql_result($users,$stats['members'] - 1,"uid"); // The id of that user
$query="SELECT * FROM mybb_threads"; // the information is stored in this table
$topics=mysql_query($query); // selects the table specifyed by the queary variable
$stats['topics'] = mysql_numrows($topics); // The amount of topics made in the forum
$query="SELECT * FROM mybb_posts"; // the information is stored in this table
$posts=mysql_query($query); // selects the table specifyed by the queary variable
$stats['posts'] = mysql_numrows($posts); // The amount of posts made in the forum
if (isset($_COOKIE[mybbuser])){ // If the cookie is set add some more variables
list($cookie["uid"], $cookie["loginkey"]) = explode("_", $_COOKIE[mybbuser]); // Splits the cookie value into the uid and the loginkey.
$cookie["lastvisit"] = $_COOKIE[mybbuser]; // The time when the forum was last visited
}
else {
echo "<p>You are currently not logged in. <a href=\"" . $forum['url'] . "member.php?action=register\">Register here.</a></p>";
} // End of ELSE
$query = sprintf("SELECT uid, username, loginkey FROM mybb_users WHERE uid='%s'",
mysql_real_escape_string($cookie["uid"]));
$thisuser = mysql_query($query);
if (!$thisuser) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
} // End of IF
while ($row = mysql_fetch_assoc($thisuser)) {
$row['uid'];
$row['username'];
$row['loginkey'];
if ((isset($_COOKIE[mybbuser])) && ($row['uid'] == $cookie["uid"]) && ($row['loginkey'] == $cookie["loginkey"])) {
echo "<p>Welcome back " . $row['username'] . ".</p>";
} // End of IF
} // End of While
mysql_close();
?>
<p>There are <?php echo $stats['posts']; ?> posts, in <?php echo $stats['topics']; ?> topics. There are currently <?php echo $stats['members']; ?> registered members.</p>
<p>Please welcome our newest member, <a href="<?php echo $forum['url']; ?>member.php?action=profile&uid=<?php echo $stats['id_member']; ?>"><?php echo $stats['latest_member']; ?></a>.</p>
thank you at first
I have upload the script on my homepage but I think my database.php is wrong (very much errors) becaus I have copy the code of the config.php in the database.php
How have to be the code of the database.php ?
Thank you
oh yeah, sorry
<?php
$forum['hostname'] = "localhost";
$forum['username'] = "db_username";
$forum['password'] = "db_password";
$forum['database'] = "db_name";
?>