PDA

View Full Version : Most viewed thread by forum ?


01-12-2001, 11:33 AM
Anyone done this yet ?

a simple page listing most viewed thread in the past X days , sorted by forum which the thread hyperlinked showing the number of replies and views

- mostviewedthread [views: xx] [replies: xx]

01-12-2001, 12:26 PM
Shows within the last 30 days.

<?
require("global.php");

$foruminfo=$DB_site->query("SELECT forumid, title FROM forum ORDER BY categoryid,displayorder");
while ($forum=$DB_site->fetch_array($foruminfo)) {
echo ("<a href=\"forumdisplay.php?forumid=".$forum[forumid]."\">".$forum[title]."</a><br>");
$threadinfo=$DB_site->query_first("SELECT threadid,title,replycount,views FROM thread WHERE forumid=$forum[forumid] and dateline > UNIX_TIMESTAMP(curdate()-30) ORDER BY views DESC LIMIT 1");
echo ("&nbsp;&nbsp;<a href=\"showthread.php?threadid=".$threadinfo[threadid]."\">".htmlspecialchars($threadinfo[title])."</a>&nbsp;[views: ".$threadinfo[views]."]&nbsp;[replies: ".$threadinfo[replycount]."]<br>");
}

?>



Demo: http://sitepointforums.com/mostviewed.php

If you want to exclude certain forums. i.e. moderator forums, then add a WHERE clause to $foruminfo... For example:
WHERE forumid<>1

01-12-2001, 12:33 PM
thanks.. is can be modified to slow the top X or 5 viewed threads per forum ?

forum 1
1. - mostviewedthread - [views: xx] [replies: xx]
2. - 2ndmostviewedthread - [views: xx] [replies: xx]
3. - 3rdmostviewedthread - [views: xx] [replies: xx]
4. - 4thmostviewedthread - [views: xx] [replies: xx]
5. - 5thmostviewedthread - [views: xx] [replies: xx]

forum 2
1. - mostviewedthread - [views: xx] [replies: xx]
2. - 2ndmostviewedthread - [views: xx] [replies: xx]
3. - 3rdmostviewedthread - [views: xx] [replies: xx]
4. - 4thmostviewedthread - [views: xx] [replies: xx]
5. - 5thmostviewedthread - [views: xx] [replies: xx]

all most forgot where forum is listed in order of diplay on forumhome page :)

thanks

[Edited by eva2000 on 01-12-2001 at 09:41 AM]

01-12-2001, 02:45 PM
The forums should already be listed in the order they are displayed in forumhome. It orders them by categoryid and then by displayorder to get the same sequence.

Here is the code where you can change the number of threads shown. Just change the LIMIT on the second Query to modify the amount.


<?
require("global.php");

$foruminfo=$DB_site->query("SELECT forumid, title FROM forum ORDER BY categoryid,displayorder");
while ($forum=$DB_site->fetch_array($foruminfo)) {
echo ("<a href=\"forumdisplay.php?forumid=".$forum[forumid]."\">".$forum[title]."</a><br>");
$threadinfo=$DB_site->query("SELECT threadid,title,replycount,views FROM thread WHERE forumid=$forum[forumid] AND dateline > UNIX_TIMESTAMP(curdate()-30) ORDER BY views DESC LIMIT 5");
while ($thread=$DB_site->fetch_array($threadinfo)) {
echo ("&nbsp;&nbsp;<a href=\"showthread.php?threadid=".$thread[threadid]."\">".htmlspecialchars($thread[title])."</a>&nbsp;[views: ".$thread[views]."]&nbsp;[replies: ".$thread[replycount]."]<br>");
}
}

?>

01-12-2001, 05:56 PM
thanks.. it works perfectly :)

http://animeboards.net/forums/mostviewed.php
although for some reason the last recent forums i added, are old of the sort and display order i have on my forums ?

01-12-2001, 06:14 PM
There seems to be a problem with your global.php file...

Warning: Cannot add header information - headers already sent by (output started at /home/animeboa/public_html/forums/mostviewed.php:7) in /home/animeboa/public_html/forums/global.php on line 756

Warning: Cannot add header information - headers already sent by (output started at /home/animeboa/public_html/forums/mostviewed.php:7) in /home/animeboa/public_html/forums/global.php on line 763

01-13-2001, 03:56 AM
btw, this is OT, but i figure its not a *bad* spot to suggest it. my board has a few threads that have over 2^16-1 views, and the counter stops there.

might wanna fix that for v2.0 :)

01-13-2001, 04:59 AM
Originally posted by wluke
There seems to be a problem with your global.php file...

Warning: Cannot add header information - headers already sent by (output started at /home/animeboa/public_html/forums/mostviewed.php:7) in /home/animeboa/public_html/forums/global.php on line 756

Warning: Cannot add header information - headers already sent by (output started at /home/animeboa/public_html/forums/mostviewed.php:7) in /home/animeboa/public_html/forums/global.php on line 763

thanks.. i had some server problems and was playing around with the formatting.. it should work now :)

01-13-2001, 12:49 PM
Nice addon but any way i can stop it displying private section posts?
thanks
cya trin

01-13-2001, 04:18 PM
Originally posted by wluke
If you want to exclude certain forums. i.e. moderator forums, then add a WHERE clause to $foruminfo... For example:
WHERE forumid<>1

01-14-2001, 10:09 AM
Thanks but No idea where to put it kept getting errors..
plz give example
thnx
cya trinity

01-14-2001, 10:32 AM
Originally posted by trinity679
Thanks but No idea where to put it kept getting errors..
plz give example
thnx
cya trinity okay something like this for the private forums


<?
require("global.php");

$foruminfo=$DB_site->query("SELECT forumid, title FROM forum WHERE forumid<>33 AND forumid<>34 ORDER BY categoryid,displayorder");
while ($forum=$DB_site->fetch_array($foruminfo)) {
echo ("<b><br><a href=\"forumdisplay.php?forumid=".$forum[forumid]."\">".$forum[title]."</a></b><br>");
$threadinfo=$DB_site->query("SELECT threadid,title,replycount,views FROM thread WHERE forumid=$forum[forumid] AND dateline > UNIX_TIMESTAMP(curdate()-30) ORDER BY views DESC LIMIT 4");
while ($thread=$DB_site->fetch_array($threadinfo)) {
echo ("???<a href=\"showthread.php?threadid=".$thread[threadid]."\">".htmlspecialchars($thread[title])."</a><font color=\"#0000ff\">?[views: ".$thread[views]."]?[replies: ".$thread[replycount]."]</font><br>");
}
}

?>

01-15-2001, 07:08 AM
Thanks i'll give it ago:p
cya trinity

01-15-2001, 07:19 PM
This is what i've done with this hack well just started mesing about with it;)


<html>
<head>
<STYLE type=text/css>BODY {
SCROLLBAR-FACE-COLOR: #336699; SCROLLBAR-HIGHLIGHT-COLOR: #cccccc; SCROLLBAR-SHADOW-COLOR: #cccccc; SCROLLBAR-3DLIGHT-COLOR: #c0c0c0; SCROLLBAR-ARROW-COLOR: #666666; SCROLLBAR-TRACK-COLOR: #808080; SCROLLBAR-DARKSHADOW-COLOR: #391918
}
</STYLE>
<STYLE type="text/css">
{font-family: helvetica,arial}
A:visited {text-decoration: none;COLOR: #ffffff}
A:link {text-decoration: none;COLOR: #ffffff}
</STYLE>

<title>Whats going on the board</title>
</head>
<body bgcolor="#336699">


<div align="left">
<table border="1" width="736" height="521">
<tr>
<td width="730" height="74">

<?php
require("global.php3");
$foruminfo=$DB_site->query("SELECT forumid, title FROM forum WHERE forumid<>2 AND forumid<>3 AND forumid<>4 AND forumid<>5 AND forumid<>6 AND forumid<>7 AND forumid<>8 AND forumid<>9 AND forumid<>10 AND forumid<>11 AND forumid<>12 AND forumid<>13 AND forumid<>14 AND forumid<>15 AND forumid<>16 AND forumid<>16 AND forumid<>17 AND forumid<>18 AND forumid<>19 ORDER BY displayorder");
while ($forum=$DB_site->fetch_array($foruminfo)) {
echo ("<b><br><a href=\"forumdisplay.php3?forumid=".$forum[forumid]."\">".$forum[title]."</a></b><br>");
$threadinfo=$DB_site->query("SELECT threadid,title,replycount,views FROM thread WHERE forumid=$forum[forumid] AND dateline > UNIX_TIMESTAMP(curdate()-30) ORDER BY views DESC LIMIT 4");
while ($thread=$DB_site->fetch_array($threadinfo)) {
echo (" ? <a href=\"showthread.php3?threadid=".$thread[threadid]."\">".htmlspecialchars($thread[title])."</a><font color=\"#000000\"> [views: ".$thread[views]."] [replies: ".$thread[replycount]."]</font><br>");
}
}
?>
</td>
</tr>
<tr>
<td width="748" height="74">
<?php

$foruminfo=$DB_site->query("SELECT forumid, title FROM forum WHERE forumid<>1 AND forumid<>3 AND forumid<>4 AND forumid<>5 AND forumid<>6 AND forumid<>7 AND forumid<>8 AND forumid<>9 AND forumid<>10 AND forumid<>11 AND forumid<>12 AND forumid<>13 AND forumid<>14 AND forumid<>15 AND forumid<>16 AND forumid<>16 AND forumid<>17 AND forumid<>18 AND forumid<>19 ORDER BY displayorder");
while ($forum=$DB_site->fetch_array($foruminfo)) {
echo ("<b><br><a href=\"forumdisplay.php3?forumid=".$forum[forumid]."\">".$forum[title]."</a></b><br>");
$threadinfo=$DB_site->query("SELECT threadid,title,replycount,views FROM thread WHERE forumid=$forum[forumid] AND dateline > UNIX_TIMESTAMP(curdate()-30) ORDER BY views DESC LIMIT 4");
while ($thread=$DB_site->fetch_array($threadinfo)) {
echo (" ? <a href=\"showthread.php3?threadid=".$thread[threadid]."\">".htmlspecialchars($thread[title])."</a><font color=\"#000000\"> [views: ".$thread[views]."] [replies: ".$thread[replycount]."]</font><br>");
}
}
?>
</td>
</tr>
</table>
</div>

i had to add - all forums but the one i wanted in the frame this way i could cose what forum was displayed first:p

hope this helps anyone thought i would share it as it looks alot better than starnard:p
cya trinity

01-15-2001, 07:23 PM
Actually if it was something that I was going to use, I would have used vBulletin's template system for display. :)

It was something that was just whipped up to answer the request...