MyBB Community Forums

Full Version: A couple of requests (Stats + Latest Posts)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello people.

I need help from a good coder who knows MyBB well. It won't be hard, It's simple MySQL query but I'm not good at MySQL so I need to ask someone to help me Big Grin

I need two little scripts.

  1. A stats script: A simple stats script which returns the total number of threads. topics, users, and forums. I had a script already made by someone on the Code Modifications Forums but they were horrible and outdated. Their script was like this:

    <?php
    $prfx = "mybb_"; // The table prefix of your database
    $topic_result = mysql_query("SELECT COUNT(*) as count FROM ".$prfx."threads");
    $topic_count = mysql_fetch_array($topic_result);
    $topic_count = $topic_count["count"];
    $post_result = mysql_query("SELECT COUNT(*) as count FROM ".$prfx."posts");
    $post_count = mysql_fetch_array($post_result);
    $post_count = $post_count["count"];
    $user_result = mysql_query("SELECT COUNT(*) as count FROM ".$prfx."users");
    $user_count = mysql_fetch_array($user_result);
    $user_count = $user_count["count"];
    $forum_result = mysql_query("SELECT COUNT(*) as count FROM ".$prfx."forums");
    $forum_count = mysql_fetch_array($forum_result);
    $forum_count = $forum_count["count"];
    ?>
    
    Stats
    <table>
     <tr>
      <td><b><?php echo $topic_count; ?></b></td>
      <td>Threads</td>
     </tr>
     <tr>
      <td><b><?php echo $post_count; ?></b></td>
      <td>Posts</td>
     </tr>
     <tr>
      <td><b><?php echo $user_count; ?></b></td><td>Users</td>
    
    

    But it's outdated and it's crappy, so all I'm asking is to get it modified and updated please.



  2. Second, a latest Posts script. A simple script to pull the latest 5 posts made and who made them and when. Again, I used someone else's but it's outdated and sucky, here it is:
    <?php
    // Posts To Show
    $max = 5;
    // Table Prefix
    $prefix = "mybb_";
    
    // Get Posts
    $query = $db->query("SELECT * FROM ".$prefix."posts ORDER BY dateline DESC LIMIT 0,$max");
    while($posts = $db->fetch_array($query))
    {
    //PostInfo
    $tid = $posts['tid'];
    $pid = $posts['pid'];
    $subject = $posts['subject'];
    $date = date("H:i / d-m", $posts['dateline']);
    //UserInfo
    $username = $posts['username'];
    $uid = $posts['uid'];
    require_once "inc/functions_user.php";
    $link = build_profile_link_for($username, $uid);
    //Posts
    $post .= "<a class=\"nav\" href=\"forum/showthread.php?tid={$tid}&pid={$pid}#pid={$pid}\">{$subject}</a> By ".$link." On ".$date."<br><br />";
    
    }
    
    echo $post;
    ?>
    

    So again, just a little updated version of it.




Thanks if anyone can help me with this. =]

PS/Edit: I'll give a cookie! Toungue
The last script is not outdated ... You don't need to know MySQL to format the output line. And sucky ? That's the only way to get the latest postinfo, with a query ... =/
LeX- Wrote:The last script is not outdated ... You don't need to know MySQL to format the output line. And sucky ? That's the only way to get the latest postinfo, with a query ... =/

I asked Tikitiki about them and he said they sucked. Also I wasn't asking for the output line, I was asking for the whole script with the MySQL queries.
DCR Wrote:
LeX- Wrote:The last script is not outdated ... You don't need to know MySQL to format the output line. And sucky ? That's the only way to get the latest postinfo, with a query ... =/

I asked Tikitiki about them and he said they sucked. Also I wasn't asking for the output line, I was asking for the whole script with the MySQL queries.

If he can provide a simplier query to get that info, he may post it ^^.
hello? datacache anyone?
Tikitiki Wrote:hello? datacache anyone?

Latest posts ? =P
Latest posts:

<?php
// DBNAME
$dbname = "";
// USERNAME
$user = "";
// PASSWORD
$password = "";
// TABLE_PREFIX
$prefix = "mybb_";
// FORUMROOT
$root = "";
// Posts To Show
$max = 5;

// Connect to db
$db = mysql_connect("localhost",$user,$password) or die ("Failure!");  
mysql_select_db($dbname,$db);

// Get Posts
$query = mysql_query("SELECT * FROM ".$prefix."posts ORDER BY dateline DESC LIMIT 0,$max");
while($posts = mysql_fetch_array($query))
{
    $tid = $posts['tid'];
    $pid = $posts['pid'];
    $subject = $posts['subject'];
    $username = $posts['username'];
    $post .= $username." <a href=\"{$root}showthread.php?tid={$tid}&amp;pid={$pid}#pid={$pid}\">{$subject}</a><br />";
}
echo $post;
?>
Kikkerkont Wrote:Latest posts:

<?php
// DBNAME
$dbname = "";
// USERNAME
$user = "";
// PASSWORD
$password = "";
// TABLE_PREFIX
$prefix = "mybb_";
// FORUMROOT
$root = "";
// Posts To Show
$max = 5;

// Connect to db
$db = mysql_connect("localhost",$user,$password) or die ("Failure!");  
mysql_select_db($dbname,$db);

// Get Posts
$query = mysql_query("SELECT * FROM ".$prefix."posts ORDER BY dateline DESC LIMIT 0,$max");
while($posts = mysql_fetch_array($query))
{
    $tid = $posts['tid'];
    $pid = $posts['pid'];
    $subject = $posts['subject'];
    $username = $posts['username'];
    $post .= $username." <a href=\"{$root}showthread.php?tid={$tid}&pid={$pid}#pid={$pid}\">{$subject}</a><br />";
}
echo $post;
?>

Yuck, that is outdated too. Why are you connecting to the database again? And this is the exact same one I posted on my first post, but without the connection again, which is still outdated.
DCR Wrote:
Kikkerkont Wrote:Latest posts:

<?php
// DBNAME
$dbname = "";
// USERNAME
$user = "";
// PASSWORD
$password = "";
// TABLE_PREFIX
$prefix = "mybb_";
// FORUMROOT
$root = "";
// Posts To Show
$max = 5;

// Connect to db
$db = mysql_connect("localhost",$user,$password) or die ("Failure!");  
mysql_select_db($dbname,$db);

// Get Posts
$query = mysql_query("SELECT * FROM ".$prefix."posts ORDER BY dateline DESC LIMIT 0,$max");
while($posts = mysql_fetch_array($query))
{
    $tid = $posts['tid'];
    $pid = $posts['pid'];
    $subject = $posts['subject'];
    $username = $posts['username'];
    $post .= $username." <a href=\"{$root}showthread.php?tid={$tid}&pid={$pid}#pid={$pid}\">{$subject}</a><br />";
}
echo $post;
?>

Yuck, that is outdated too. Why are you connecting to the database again? And this is the exact same one I posted on my first post, but without the connection again, which is still outdated.

Cause that's the only way to get the latest posts like i told you already ... the stats you can get from the cache, not the latest posts.
As long as it works I don't really give a orange if it's outdated. Toungue