function top_posters()
{
$cur_time = mktime(date(G), date(i), date(s), date(m), date(d), date(Y));
$query = 'SELECT userid, username, posts ' .
'FROM user ' .
'ORDER BY posts DESC LIMIT 3';
$result = mysql_query($query)
or die('top_posters query failed');
return($result);
}
?>
IRC may recognise this :)
My question is, is there a way to set this so it displays the top posters of the last 7 days and the number of posts during that time period?
I had tried changing some things and got the top list for last 7 days, but it would only display the total number of posts, not just for those 7 days..
I hope Im making sense.
I did something like this only I calculate based on the past 24 hours.
$numberHighPostPerPage = 10; //set for this paste of teh script
$curTime = localtime();
$uts = time() - ($curTime[2]*3600 + $curTime[1]*60 + $curTime[0]);
$lts = $uts - (86401); // 3600 * 24 + 1 (to be completely honest about "yesterday")
unset($curTime);
$users = $DB_site->query("
SELECT post.userid, user.username, COUNT(post.userid) AS count
FROM post
LEFT JOIN user ON post.userid=user.userid
WHERE dateline >= $lts AND dateline <= $uts
GROUP BY post.userid
ORDER BY count DESC
LIMIT $numberHighPostPerPage"
);
$numberHighPostPerPage = 10; //set for this paste of the script
$curTime = localtime();
$uts = time() - ($curTime[2]*3600 + $curTime[1]*60 + $curTime[0]);
$lts = $uts - (604800); // 3600 * 24 + 1 (to be completely honest about "yesterday")
unset($curTime);
$users = $DB_site->query("
SELECT post.userid, user.username, COUNT(post.userid) AS count
FROM post
LEFT JOIN user ON post.userid=user.userid
WHERE dateline >= $lts AND dateline <= $uts
GROUP BY post.userid
ORDER BY count DESC
LIMIT $numberHighPostPerPage");
Parse error: parse error in /www/influx9/forum/ztoppost.php(23) : eval()'d code on line 1
Parse error: parse error in /www/influx9/forum/ztoppost.php(23) : eval()'d code on line 1
Parse error: parse error in /www/influx9/forum/ztoppost.php(23) : eval()'d code on line 1
Parse error: parse error in /www/influx9/forum/ztoppost.php(23) : eval()'d code on line 1
Parse error: parse error in /www/influx9/forum/ztoppost.php(23) : eval()'d code on line 1
Parse error: parse error in /www/influx9/forum/ztoppost.php(23) : eval()'d code on line 1
Parse error: parse error in /www/influx9/forum/ztoppost.php(23) : eval()'d code on line 1
Parse error: parse error in /www/influx9/forum/ztoppost.php(23) : eval()'d code on line 1
Parse error: parse error in /www/influx9/forum/ztoppost.php(23) : eval()'d code on line 1
Parse error: parse error in /www/influx9/forum/ztoppost.php(23) : eval()'d code on line 1
Parse error: parse error in /www/influx9/forum/ztoppost.php(31) : eval()'d code on line 1
hey leadZERO
Can you post your templates?
The reason why you are getting parse errors is not because of a coding error on anyone's part.
It is a problem that vBulletin currently has with [ php ] blocks and escaped characters... watch this:
eval("\$bits .= \"".gettemplate("bit")."\";"); now the same code in a [ php ] block: eval("\$bits .= \"".gettemplate("bit")."\";"); As you can see, the code is not properly printed in the PHP block.
I did manage to get rid of the parse errors.. :) Trying to sort the templates now :p
Those are copied straight from my templates, so just ignore things like my spacer GIF.
Works great leadZERO, I appreciate the help!
Originally posted by Kier
As you can see, the code is not properly printed in the PHP block.
Maybe it's cause Freddie fixed it (haven't looked for this specifically in the Bug Fixes thread yet) but they look exactly the same to me...
The \ is missing before $bits
Bane I got the same parse error as you. What did you do to fix it?
how do I change this code so I can run it in a different directory then my forum?
Snyx, I am running it through a SSI Include
<!-- include virtual="/forum/toppost.php"-->
Is this what you need? or you want to keep the file in a non forum directory?
Sarge, here is the corrected file: (Set for top posters in last 7 days)
Tried your attached file but Im getting this error:
Fatal error: Call to unsupported or undefined function localtime() in /home/sites/home/web/forum/toppost.php on line 7
When I try to call the .php in I get a bunch of NONSCENCE! Hummmm, I donno . . . .
Ok Thanks Bane
MY question... I posted on my test board just to check this out,
but it listed the top posters... not the top posters from the last 24!
IT is supposed to list the top posters from the last 24 right?
He changed my original version to display for the past seven days or something. Change the number of seconds difference between $uts and $lts to whatever 3600*24+1 is.
This seems to be cool. I wonder if you guys can modify the codes so i get a list of the last 10 posts (messages) instead of 10 posters!
just wondering....
<?php
// Set this to the max number of threads to display
$maxthreads = 10;
require("./admin/config.php");
$db=mysql_connect($servername,$dbusername,$dbpassword);
mysql_select_db($dbname);
$query = "SELECT * FROM thread ORDER BY lastpost DESC LIMIT $maxthreads";
$resultlatest = mysql_query($query,$db);
while ($latest_array = mysql_fetch_array($resultlatest)) {
echo "<a href=\"showthread.php?threadid=$latest_array[threadid]\">$latest_array[title]</a>";
}