I am trying to get a daily top posters count for a block on my front page. I have it working, but it goes 24 hours back from the time of the last post by each member on the list (from the way I understand it)... is there a code that I could use that would go from midnight server time until midnight server time each day and reset at midnight? Or even a way to modify what I have? (Please keep in mind I am barely PHP literate)
Here's what I am using... pretty sure it came from THIS (http://www.tinyportal.net/index.php?topic=8762.0) thread LOL but I was having problems getting pages to load using IE7 so had to switch to Opera and find it all over again.
global $db_prefix, $scripturl, $memberContext, $txt, $modSettings;
$maxlength=20;
// $starttime = strtotime('24 hours ago'); //posters laatste 24 uur
$starttime = mktime(0, 0, 0, date('m'), date('d'), date('Y')); //posters vandaag
$list_count = 10;
$poster = array();
$request = db_query("
SELECT m.ID_MEMBER, COUNT(m.ID_MEMBER) as postCount
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
WHERE m.posterTime > " . $starttime . "
AND t.ID_TOPIC = m.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
GROUP BY m.ID_MEMBER
ORDER BY postCount DESC LIMIT " . $list_count, __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
{
loadMemberData(array($row['ID_MEMBER']));
loadMemberContext($row['ID_MEMBER']);
$membername = (strlen($memberContext[$row['ID_MEMBER']]['name']) > $maxlength) ? substr($memberContext[$row['ID_MEMBER']]['name'],0,$maxlength) : $memberContext[$row['ID_MEMBER']]['name'];
$poster[$row['ID_MEMBER']] = array (
'id' => $row['ID_MEMBER'],
'count' => $row['postCount'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" title="' . $txt[92] . ' ' . $memberContext[$row['ID_MEMBER']]['name'] . '">' . '<font color="' . $memberContext[$row['ID_MEMBER']]['group_color'] . '">' . $membername . '</font>' . '</a>' );
}
mysql_free_result($request);
echo '<table width=100%>';
foreach($poster as $top_user)
{
echo '<tr>
<td align="right" width=75%>' . $top_user['link'] . '</td>
<td align="left">| '. $top_user['count'] . '</td>
</tr>';
}
echo '</table>';
I am pretty sure that the part that I would need to change would be in this section somewhere, but I have no idea what to change it to.
// $starttime = strtotime('24 hours ago'); //posters laatste 24 uur
$starttime = mktime(0, 0, 0, date('m'), date('d'), date('Y')); //posters vandaag
$list_count = 10;
Please and thank you in advance!
Here's my forum LINK (http://psp-n-pixels.com/forum) in case anyone needs it, though I am not totally sure what you can see as a guest.
SMF 1.1.3
TinyPortal v0.9.8
No errors, just not doing what I want.
(YES there is a reason why I haven't upgraded to the new versions... but that's a totally different support topic)
I think what you want is already there but commented out, move the double // to the second line to swap what is being used
Change // $starttime = strtotime('24 hours ago'); //posters laatste 24 uur
$starttime = mktime(0, 0, 0, date('m'), date('d'), date('Y')); //posters vandaag
To $starttime = strtotime('24 hours ago'); //posters laatste 24 uur
// $starttime = mktime(0, 0, 0, date('m'), date('d'), date('Y')); //posters vandaag
Ahh, re-read your post. This change does last 24hours from now but does not reset at midnight like you want.
Also, you may wish to have it start from midnight "users time" instead of "server time" if you are going to label it as "top posters for today"
Otherwise it won't be true for people in different time zones different to your server location.
Sorry I can't help with the question, bit beyond me. :)
Could you try
Changing:
// $starttime = strtotime('24 hours ago'); //posters laatste 24 uur
$starttime = mktime(0, 0, 0, date('m'), date('d'), date('Y')); //posters vandaag
To:
$starttime = strtotime("00:00");
Or (to base it off of forum's midnight):
$starttime = strtotime("00:00") + $modSettings['time_offset'] * 3600;