PDA

View Full Version : Top Viewed threads


duke
02-11-2002, 09:46 PM
Im trying to disply the top viewed threads and did now find a hack to do this. So I tried this but it dont work any ideas on how I can complete this.

// Top 10 Viewed Threads//

$top = "10"; // change this to the number of top thread views you want to disply.

echo("<table border=0 cellpadding=0 cellspacing=0><tr><td><b>Top Viewed Threads </b></td></tr>");

$topthread = mysql_query("SELECT COUNT(*) AS count,title,views FROM thread ORDER BY count DESC LIMIT $top;");
$lugar=1;
while ($topview = mysql_fetch_array($topthread)):
if (($counter++ % 2) != 0);

echo("<tr><td><strong><big>&middot;</big></strong>&nbsp;$lugar: <a href=\"$bburl/showthread.php?&$topthread[title]\">$topthread[threadid]</a></td><td align=\"center\">$topthreads[views]</td></tr>");
$lugar++;
endwhile;

echo("</table>");
echo("<br>");

duke
02-12-2002, 01:08 AM
I got it to work with this code I just need some help with excluding some forums form it any ideas how to do this

// Top 10 Viewed Threads//

$top = "10"; // change this to the number of posters you want to show.

echo("<table border=0 cellpadding=4 cellspacing=0><tr><td><b>Top 10 Viewed Threads</b></td><td><br>");
echo("</table>");
echo("<table border=0 cellpadding=0 cellspacing=0><tr><td><b>Thread</b></td><td><b>Viewed</b></td></tr>");

$postsresult = mysql_query("SELECT COUNT(*) AS count,threadid,title,views,forumid FROM thread GROUP BY threadid ORDER BY views DESC LIMIT $top;");
$lugar=1;
while ($vthreads = mysql_fetch_array($postsresult)):
if (($counter++ % 2) != 0);

echo("<tr><td><strong><big>ยท</big></strong> $lugar: <a href=\"$bburl/showthread.php?s&threadid=$vthreads[threadid]\">$vthreads[title]</a></td><td align=\"center\">$vthreads[views]</td></tr>");
$lugar++;
endwhile;

echo("</table>");
echo("<br>");

Admin
02-12-2002, 09:49 AM
Add:
WHERE forumid NOT IN (1,2,3,4,5,...)
to exclude forums.

duke
02-12-2002, 01:15 PM
Thanks for the help, When tried

WHERE forumid NOT IN (1,2,3,4,5,...)

I got mysql errors

so I tried this and it works

WHERE forumid<>'1,2,3,4,5'

Admin
02-12-2002, 01:24 PM
But it's not correct, because you checking that the forumid is not equal to the STRING '1,2,3,4,5'. Use my code without the ... (I thought that was obvious).

duke
02-12-2002, 02:05 PM
Ok thanks, I had it right the first time I tried your code, I had a nother error in the code that was causing my error I just found

Thanks for the Help