[For 1.8] Today's Statistics
#1
Just a simple tutorial on how to output the today's stats that's been made (posts, threads, registrations & active users).

1. Open up index.php and find this code

if($mybb->user['uid'] != 0)
{
    eval('$logoutlink = "'.$templates->get('index_logoutlink').'";');
}

2. After that code, add


//Gets new posts today.
    $timecut = TIME_NOW - 86400;

    $query = $db->simple_select("posts", "COUNT(*) AS newposts", "dateline > '$timecut' AND visible='1'");
    $newposts = my_number_format($db->fetch_field($query, "newposts"));

    
    //Gets new threads today.
    $timecut = TIME_NOW - 86400;

    $query = $db->simple_select("threads", "COUNT(*) AS newthreads", "dateline > '$timecut' AND visible='1' AND closed NOT LIKE 'moved|%'");
    $newthreads = my_number_format($db->fetch_field($query, "newthreads"));
    
    
    //Gets new users today.
    $timecut = TIME_NOW - 86400;

    $query = $db->simple_select("users", "COUNT(uid) AS newusers", "regdate > '$timecut'");
    $newusers = my_number_format($db->fetch_field($query, "newusers"));
    
    //Gets total active users today.
    $timecut = TIME_NOW - 86400;

    $query = $db->simple_select("users", "COUNT(uid) AS activeusers", "lastvisit > '$timecut'");
    $activeusers = my_number_format($db->fetch_field($query, "activeusers"));

3. Now you can output these in the index template like this:


{$newposts} New posts
{$newthreads} New threads
{$newusers} New users
{$activeusers} Active users


I hope you enjoyed the simple tutorial.  Toungue
Reply
#2
(2015-08-12, 10:33 PM)Sazze Wrote: Just a simple tutorial on how to output the today's stats that's been made (posts, threads, registrations & active users).

1. Open up index.php and find this code

if($mybb->user['uid'] != 0)
{
    eval('$logoutlink = "'.$templates->get('index_logoutlink').'";');
}

2. After that code, add


//Gets new posts today.
    $timecut = TIME_NOW - 86400;

    $query = $db->simple_select("posts", "COUNT(*) AS newposts", "dateline > '$timecut' AND visible='1'");
    $newposts = my_number_format($db->fetch_field($query, "newposts"));

    
    //Gets new threads today.
    $timecut = TIME_NOW - 86400;

    $query = $db->simple_select("threads", "COUNT(*) AS newthreads", "dateline > '$timecut' AND visible='1' AND closed NOT LIKE 'moved|%'");
    $newthreads = my_number_format($db->fetch_field($query, "newthreads"));
    
    
    //Gets new users today.
    $timecut = TIME_NOW - 86400;

    $query = $db->simple_select("users", "COUNT(uid) AS newusers", "regdate > '$timecut'");
    $newusers = my_number_format($db->fetch_field($query, "newusers"));
    
    //Gets total active users today.
    $timecut = TIME_NOW - 86400;

    $query = $db->simple_select("users", "COUNT(uid) AS activeusers", "lastvisit > '$timecut'");
    $activeusers = my_number_format($db->fetch_field($query, "activeusers"));

3. Now you can output these in the index template like this:


{$newposts} New posts
{$newthreads} New threads
{$newusers} New users
{$activeusers} Active users


I hope you enjoyed the simple tutorial.  Toungue

Which index template mate??
Reply
#3
(2015-08-15, 02:06 PM)Darth Vader Wrote:
(2015-08-12, 10:33 PM)Sazze Wrote: Just a simple tutorial on how to output the today's stats that's been made (posts, threads, registrations & active users).

1. Open up index.php and find this code

if($mybb->user['uid'] != 0)
{
    eval('$logoutlink = "'.$templates->get('index_logoutlink').'";');
}

2. After that code, add


//Gets new posts today.
    $timecut = TIME_NOW - 86400;

    $query = $db->simple_select("posts", "COUNT(*) AS newposts", "dateline > '$timecut' AND visible='1'");
    $newposts = my_number_format($db->fetch_field($query, "newposts"));

    
    //Gets new threads today.
    $timecut = TIME_NOW - 86400;

    $query = $db->simple_select("threads", "COUNT(*) AS newthreads", "dateline > '$timecut' AND visible='1' AND closed NOT LIKE 'moved|%'");
    $newthreads = my_number_format($db->fetch_field($query, "newthreads"));
    
    
    //Gets new users today.
    $timecut = TIME_NOW - 86400;

    $query = $db->simple_select("users", "COUNT(uid) AS newusers", "regdate > '$timecut'");
    $newusers = my_number_format($db->fetch_field($query, "newusers"));
    
    //Gets total active users today.
    $timecut = TIME_NOW - 86400;

    $query = $db->simple_select("users", "COUNT(uid) AS activeusers", "lastvisit > '$timecut'");
    $activeusers = my_number_format($db->fetch_field($query, "activeusers"));

3. Now you can output these in the index template like this:


{$newposts} New posts
{$newthreads} New threads
{$newusers} New users
{$activeusers} Active users


I hope you enjoyed the simple tutorial.  Toungue

Which index template mate??

As long it's in one of the templates inside "Index Templates" it will work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)