1 (edited by Jonka 2005-02-13 22:33)

Topic: punBB wap stats and last posts

Thought i would share this...

Made a little page that displays some stats about punBB on a wap phone. It also displays the last 5 entries in all of the forums. Use it if you like. At own risk.
The code isn't perfect, i know... but it works for me, when im on the bus, curious about whats going on in the forum. Crit away!

By the way, thanks for a great forum punBB crew!

Just copy/paste the code, save it as a .php file where your forum sits with access to the mySQL database. Then access it with your phone.


 
<?php 
// Browse some punBB stuff with a wap phone. by Jonka, jonka@phreaker.net
// Use at own risk, no error handling included.
// And please dont bug me with how bad my code is, i am a beginner, just cutting/pasting and some coding.

// send wml headers      (to test the script in a browser, comment out the next  line "header etc"
header("Content-type: text/vnd.wap.wml");   // this one...

// user details
$username="username";   // your mySQLusername
$password="password";   // password for the same
$database="data"; // the name of your database
$hostname="localhost";  // the hostname
$t_users="users";    // the table users in your mySQL, change the name if you changed it during punBB setup
$t_topics="topics";  // as above  topics table
$t_posts="posts";    // as above  posts table
$t_online="online";  // as above online table

// Connect to mySQL and db
$connection=mysql_connect($hostname, $username, $password) or die("Could not connect to MySQL.");
$db=mysql_select_db($database, $connection) or die( "Unable to select database");

//  No of users regged
$query="SELECT COUNT(id)-1 FROM $t_users";
$result=mysql_query($query);
$antalUsers = mysql_result($result, '0'); 

// Latest regged
$query="SELECT username FROM $t_users ORDER BY registered DESC LIMIT 1";
$result=mysql_query($query);
$senast = mysql_result($result, 0);

// No of topics
$query="SELECT COUNT(id) FROM $t_topics";
$result=mysql_query($query);
$antalTopics = mysql_result($result, '0'); 

// No of posts
$query="SELECT COUNT(id) FROM $t_posts";
$result=mysql_query($query);
$antalPosts = mysql_result($result, '0'); 

// Guests + regged online
$query="SELECT COUNT(user_id) FROM $t_online";
$result=mysql_query($query);
$online = mysql_result($result, '0'); 

    mysql_free_result($result);
    
$query="SELECT $t_posts.poster, $t_posts.message, $t_posts.posted, $t_posts.topic_id, $t_topics.id, $t_topics.subject, $t_posts.id
FROM $t_posts, $t_topics WHERE $t_posts.topic_id = $t_topics.id
ORDER BY $t_posts.posted DESC LIMIT 5";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;

echo "<?xml version=\"1.0\"?>"; 
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">"; 

?> 

<wml> 
<?php // the title of the wap page?> 
<card id="card1" title="Forum stats">

<p> 
<?php 
echo "<b>".$antalUsers." </b> users, most recent <b> ".$senast. "</b>.<br/>";
print "Right now <b> ".$antalPosts." </b> posts in <b> ".$antalTopics." </b> topics.<br/><br/>";

while ($i < $num) {
    $poster=mysql_result($result,$i,"$t_posts.poster");
    $message=mysql_result($result,$i,"$t_posts.message");
    $posted=date("ymd H:i",mysql_result($result,$i,"$t_posts.posted"));
    $subject=mysql_result($result,$i,"$t_topics.subject");
    
    echo "<i> ".$posted. " </i> ".$poster." <b> ".$subject." </b><br/> <small> ".$message." </small> <br/><br/>";
$i++;
}
?> 
</p> 
</card> 
</wml>

/Jonka

Re: punBB wap stats and last posts

It also works 'online' if you take out the 'wap' references.
Thanks for that Jonka. Its almost what I've been looking for. I'm no php/mysql expert, but I'd like to adapt your code to show, from the most recently active topic, the topic name, the topic originator and the text from the first post in that topic.
Any suggestions how to do this?
Thanks