Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 4255
Latest: andreios
New This Month: 3
New This Week: 1
New Today: 0
Stats
Total Posts: 43259
Total Topics: 7518
Most Online Today: 201
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 1
Guests: 199
Total: 200

Author Topic: Changing a recount script  (Read 4114 times)

0 Members and 1 Guest are viewing this topic.

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Changing a recount script
« on: September 18, 2014, 12:15:07 pm »
I found this script that recounts all stats found in the forum history of the stats action - the part at the bottom. Unfortunately, of the four things it recounts: date, topics, posts, registers, only posts are counted correctly. Here's the script:

Code: [Select]
<?php
require_once('SSI.php');
if (!
defined('SMF'))
die('Hacking attempt...');

recountForumStats();

function 
recountForumStats() {
    global 
$context$db_prefix;

//Lets gather data first
    
$request db_query("
        SELECT DATE(FROM_UNIXTIME(m.posterTime)) AS for_date, COUNT(m.ID_MSG) as message_count, COUNT(DISTINCT t.ID_TOPIC) as topic_count
        FROM 
{$db_prefix}messages as m
INNER JOIN 
{$db_prefix}topics AS t ON (t.ID_TOPIC = m.ID_TOPIC)
        GROUP BY DATE(FROM_UNIXTIME(m.posterTime))"
,
    
__FILE____LINE__);
    
$data = array();
while ($row mysql_fetch_assoc($request))
{
$data[$row['for_date']] = array(
            
'message_count' => $row['message_count'],
            
'topic_count' => $row['topic_count'],
        );
}
mysql_free_result($request);

$request db_query("
        SELECT DATE(FROM_UNIXTIME(mem.dateRegistered)) AS for_date, COUNT(mem.ID_MEMBER) as member_count
        FROM 
{$db_prefix}members as mem
        GROUP BY DATE(FROM_UNIXTIME(mem.dateRegistered))"
,
    
__FILE____LINE__);
    
$mem_data = array();
while ($row mysql_fetch_assoc($request))
{
$mem_data[$row['for_date']] = array(
            
'member_count' => $row['member_count'],
        );
}
mysql_free_result($request);

//Lets merge the arrays
$mergeData = array();
foreach($data as $key => $value) {
if(array_key_exists($key$mem_data)){
$mergeData[$key] = array(
'message_count' => $value['message_count'],
'topic_count' => $value['topic_count'],
'member_count' => $mem_data[$key]['member_count']
);
unset($mem_data[$key]);
} else {
$mergeData[$key] = array(
'message_count' => $value['message_count'],
'topic_count' => $value['topic_count'],
'member_count' => 0
);
}
}

//lets add left out members
foreach($mem_data as $key => $value) {
$mergeData[$key] = array(
'message_count' => 0,
'topic_count' => 0,
'member_count' => $value['member_count']
);
}

    foreach(
$mergeData as $key => $val) {
$time strtotime($key);
$myDate date('Y-m-d'$time);

        
$request db_query("
            REPLACE INTO 
{$db_prefix}log_activity (date, topics, posts, registers) values('$myDate', $val[topic_count]$val[message_count]$val[member_count])",
        
__FILE____LINE__);
    }
}

?>

How do I change this part of the script so that only the posts are replaced while date, topics, and registers stay the way they are?

Code: [Select]
REPLACE INTO {$db_prefix}log_activity (date, topics, posts, registers) values('$myDate', $val[topic_count], $val[message_count], $val[member_count])",
        __FILE__, __LINE__);

Actual script can be found here: https://github.com/siddhartha-gupta/SMF-RecountForumStats/blob/master/Recount.php

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Changing a recount script
« Reply #1 on: September 19, 2014, 08:52:53 pm »
You should break out each query for a count into a separate query multiple counts() in one query can have unexpected results.
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Changing a recount script
« Reply #2 on: September 20, 2014, 01:06:58 am »
Code: [Select]
REPLACE INTO {$db_prefix}log_activity (posts) values($val[message_count])",
        __FILE__, __LINE__);

If I try this instead, it doesn't work. :-\

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Changing a recount script
« Reply #3 on: September 20, 2014, 09:48:27 am »
Well you should probably do an update statement instead of replace. and update based on the date column
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

 

Related Topics

  Subject / Started by Replies Last post
4 Replies
5782 Views
Last post November 22, 2006, 03:05:58 pm
by tambitch
2 Replies
3609 Views
Last post January 24, 2007, 09:52:40 pm
by mlinvin
0 Replies
3603 Views
Last post January 24, 2010, 04:50:03 pm
by SMFHacks
0 Replies
2893 Views
Last post March 15, 2010, 10:58:36 am
by TeeJay
3 Replies
3695 Views
Last post May 29, 2012, 06:43:04 pm
by SMFHacks

+- Recent Topics

No thumbnails on new uploads by SMFHacks
March 27, 2024, 02:10:41 pm

Display the Contact Page for guests by SMFHacks
March 27, 2024, 10:55:43 am

is it possible to add support for odysee.com by fvlog19
March 21, 2024, 08:47:51 am

Request for admin notification by davejo
March 10, 2024, 01:31:59 am

I need help with torrent upload by Ineedsmfhelp
March 09, 2024, 10:01:13 pm

an idea for new mod (( content type with different display )) by SMFHacks
February 27, 2024, 01:36:27 pm

[Mod] RSS Feed Poster by SMFHacks
February 27, 2024, 11:57:18 am

find duplicate pictures by fvlog19
February 14, 2024, 02:22:40 pm

Error uploading video. by SMFHacks
February 08, 2024, 02:04:16 pm

Gallery icon as last added image by fvlog19
February 01, 2024, 01:04:56 pm

Powered by EzPortal