PDA

View Full Version : Table of most "popular" threads.


irc
19 Feb 2001, 15:49
I added a simple table to my home page to let people see a list of the most viewed messages that have recieved a reply in the last week. It's based on a relatively simple query. The coding isn't anything special. I just thought people might like to see it. I plan on adding other tables for most recent new threads, etc.

Click below to here to the table: [ IRC Home Page (http://www.improvisation.ws/) ]

19 Feb 2001, 21:24
can i get this hack somewhere??? :D
plz

19 Feb 2001, 22:01
I'll try to get it in some sort of portable version for ya and post it here later.

19 Feb 2001, 22:39
Kewl! :)

19 Feb 2001, 23:22
Can make it to show most popular threads in last week instead of threads that recieved replies last week?

I think its more efficient this way.

19 Feb 2001, 23:33
You mean show the threads that got the most views in the past week?

That would a much more extensive hack. The database only keeps track of the number of views, not when they occured. This is just a simple query which runs off existing data. This was the quickest and easiest comprimise I could come up with.

However, you could do different queries based on when the thread was first created. You could exclude all threads which were created more than a week ago, for instance. That would be an easy query.

19 Feb 2001, 23:43
No, of course I didn't mean to show threads based on the most views last week. I meant what you said in the second part. However, I think there is no date for each thread. There is only (threadid) which I think can be used. So you can actually show the 10 most popular threads from the last 100 threads or 1000. I don't think you can do it based on time like week or so. I might be wrong though.

20 Feb 2001, 16:02
hmmm... there are two timestamps for each thread. The first one is for "lastpost" which is what I used in my query. The second one is called "dateline". I have to run off to work or I would investigate it further to see whether that corresponds to the timestamp for the first post. If not, you could do another query looking for the first post in each thread. A bit more work but certainly doable.

20 Feb 2001, 20:01
Yeah,, about the dateline I noticed it. But didn't figure out what it is.

20 Feb 2001, 20:27
DATELINE is when the thread was created.

20 Feb 2001, 20:53
Originally posted by wluke
DATELINE is when the thread was created.

perfect, that means we can easily do the hack based on the first post date,, this can be good for news ordering.

21 Feb 2001, 13:04
Could you post the source you used for that original hack ? I really like it

21 Feb 2001, 14:59
I will post it later today. Sorry, I've been really busy at work.

21 Feb 2001, 20:15
<?php

require("global.php");

$db_link = @mysql_pconnect("$dbservername", "$dbusername", "$dbpassword");
mysql_select_db("$dbname");

?>

<table cellpadding="4" cellspacing="1" width="100%">
<tr>
<td><small><strong>MOST VIEWED MESSAGES FROM THE PAST 7 DAYS</strong></small></td>
<td align="center"><small><strong>REPLIES</strong></small></td>
<td align="center"><small><strong>VIEWS</strong></small></td>
</tr>
<?php
$mostviewed = most_viewed();
while( $row = mysql_fetch_row($mostviewed) )
{
print('<tr>');
print('<td>');
print('<a href="showthread.php?s=&threadid=');
print($row[0]);
print('" target="_top">');
print($row[1]);
print('</a></td>');
print('<td align="center">');
print($row[2]);
print('</td>');
print('<td align="center">');
print($row[3]);
print('</td>');
print('</tr>');
}
mysql_free_result ($mostviewed);
?>
</table>

<?php

function most_viewed()
{
$cur_time = mktime(date(G), date(i), date(s), date(m), date(d), date(Y));
$query = 'SELECT threadid, title, replycount, views ' .
'FROM thread ' .
'WHERE (' . $cur_time . '-lastpost) < 604800 ' .
'ORDER BY views DESC LIMIT 10';
$result = mysql_query($query)
or die('most_viewed query failed');
return($result);
}

?>

Here you go. I took out most of the formatting tags so that you can put in your own to make it look the way you want. Put this file into same folder as global.php and let me know how it goes. :P

21 Feb 2001, 20:54
Ir rulez man !

Just a question , I try to adjust the fonts to size=1 that works with everything except for this part

print('<tr>');
print('<td>');
print('<font size=1><a href="showthread.php?s=&threadid=</font>');
print($row[0]);
print('" target="_top">');
print($row[1]);
print('</a></td>');
print('<td align="center">');
print($row[2]);
print('</td>');
print('<td align="center">');
print($row[3]);
print('</td>');
print('</tr>');

Where sould I add <font size=1> etc ... ? I know it's easy , but I'm not really a php wizard

Thanks for the GREAt script

ps:Is it possible to make the script rank them by most REPLIES instead of VIEWS or is that too hard ?
anywayz ,it rox allready !

GOOD JOB IRC



Thanks

21 Feb 2001, 21:32
To have it order by replies, you can change the line:

'ORDER BY views DESC LIMIT 10';
to
'ORDER BY replycount DESC LIMIT 10';

Put the font tags here:


print('<tr>');
print('<td><font size="1">');
print('<a href="showthread.php?s=&threadid=');
print($row[0]);
print('" target="_top">');
print($row[1]);
print('</a></font></td>');
print('<td align="center"><font size="1">');
print($row[2]);
print('</font></td>');
print('<td align="center"><font size="1">');
print($row[3]);
print('</font></td>');
print('</tr>');

22 Feb 2001, 16:28
Something else first , do I add the able border/color options at the same spots you add the font tags ?


Now the serious question , I posted earlier that I need this kind of hack , but for the TOP POSTER (so not a link to a certain post) So just a list that shows us who are the top 3 posters on the forum

Something like this

TOP POSTERS

UserA 188 POSTS
USERB 150 POSTS
UserC 100 POSTS

22 Feb 2001, 16:44
It shouldn't be too hard to get something that does what you want. I will work take a look at doing that for you.

As for where to put various formatting tags for the table. For tags that affect the whole table like cellpadding and border size, put them in the <table> tag. For the bgcolor or alignment of individual cells, put them in the <td> tags.

I would consult a source on HTML. Once you know where to put a tag if the file was purely HTML, it is usually easy to find out where to put in a PHP file.

22 Feb 2001, 17:01
Here you go. Again I have stripped out most of the formatting stuff so you can add your own specificiations.


<?php

require("global.php");

$db_link = @mysql_pconnect("$dbservername", "$dbusername", "$dbpassword");
mysql_select_db("$dbname");

?>

<table cellpadding="4" cellspacing="1" width="100%">
<tr>
<td><small><strong>TOP POSTERS</strong></small></td>
<td align="center"><small><strong>POSTS</strong></small></td>
</tr>
<?php
$top_post = top_posters();
while( $row = mysql_fetch_row($top_post) )
{
print('<tr>');
print('<td>');
print('<a href="member.php?s=&action=getinfo&userid=');
print($row[0]);
print('" target="_top">');
print($row[1]);
print('</a></td>');
print('<td align="center">');
print($row[2]);
print('</td>');
print('</tr>');
}
mysql_free_result ($top_post);
?>
</table>

<?php

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);
}

?>

Remember, the file must be residing in the same folder as global.php to work correctly. Also, take off the .txt at the end when you put in on the server.

22 Feb 2001, 17:05
Of course as soon as I post it I realize that there is an unnecessary line of code in it. Delete this line:

$cur_time = mktime(date(G), date(i), date(s), date(m), date(d), date(Y));

22 Feb 2001, 18:24
Dude , in 2 days you have solved all my problems :) YOU RULE !

Thanks a 100000000 times

22 Feb 2001, 23:12
I think I'm going to create a whole page for my users with all kinds of stats. It will use some of the default settings for the board formatting to make it look like part of the board. I'll post it here when I'm done. It might take a week or two to do it.

05 Mar 2001, 17:14
I saw your script IRC and I changed it a litle bit to a headline script, for me is this more interesting. Good work IRC, simple but efficient your script ;)

The change:



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------

05 Mar 2001, 18:59
Hi,
I really like this script. I would LOVE to put it in my front page.

But.. I'm new to hacking vB. If someone has time to explain to me how I can incorp this into my homepage (Where to put the code, how to modify it so it works) that'd be GREAT.. Once again, great job on the script. Thanks for your time

-esoin

05 Mar 2001, 19:45
http://3dwin.gamesmania.de/main/index.php

Now you can see the headlinescript in action :D :D :D


Very fine!

07 Mar 2001, 16:41
IRC, I'm liking the script....Your most recent upload, does that include the "Most Popular In The Past Week" feature?

07 Mar 2001, 16:56
The first attachment ranks threads by most views. They have to have had a reply in the last week to qualify.

I haven't had a chance to create my crazy page of message board stats yet. Any requests for features? Here are a few ideas of mine:
Top 5 threads of all time (replies)
Top 5 threads of all time (views)
Top 5 most popular polls (votes)
Top 5 posters of all time
Five newest threads
Top 10 threads of the week (new threads only, in terms of views)
Top 10 threads of the week (new threads only, in terms of replies)

09 Mar 2001, 00:04
How are you displaying it on your main page? I tried include("./forums/popular.php"); but I get the error "Fatal error: Failed opening required './admin/config.php' (include_path='') in /home/users/x/xtremetuning.net-71707/public_html/forums/global.php on line 48"

I can get it to work if I use xtremetuning.net/forums/popular.php but I want to include it in my main page.

Thanks,

-JRW

09 Mar 2001, 15:11
Two solutions. One is to put the popular script in frames. Then you can put each individual frame whereever you want. However a better solution is described in another thread.

*searching for thread*

Here it is:
http://www.vbulletin.com/forum/showthread.php?s=&threadid=9452

I haven't had the chance to try out that solution. Let me know how it works.

09 Mar 2001, 16:49
Thanks, it worked perfectly. I still have a problem though. I already called a header which is used through out my main site, but this then calls the header function for vbulletin. I suppose I simply need to intigrate the two headers into one file to take care of this.

Thanks for your help,

-JRW

09 Mar 2001, 19:35
How can I add in the number of logged-in users at the bottom as well as who made the last post at the end of the replies/views section?

-Rob

12 Mar 2001, 15:38
I am working on making my home page completly templated and i will be adding a lot of this stuff to it. If anyone want to see it i will see if i can get it portalable.

13 Mar 2001, 02:27
Grrr...

I've been trying to use this code for the past WEEK.. I can't get it to work. I'm a VERY BEGINNER PHP user... So.. that's probably why... this is what I would do.

I would copy and paste the whole script into the HTML CODE of dreamweaver... Then I'd fill in all these..
("global.php") - I point this to my global.php file

$db_link = @mysql_pconnect
("$dbservername",) - not sure what goes here
"$dbusername", ) - I put in my vB database user name
"$dbpassword"); - I put in my vB database password

mysql_select_db("$dbname"); - I put in my vB database name'

what else am I missing? am i using the right method in incorp. this in my html? Please help. Thanks

-esoin

13 Mar 2001, 08:07
NO!
Cut ans paster that into notepad and name it popular.php.


You then call it into your page using ssi

ICQ me and I will show you how
Chris

13 Mar 2001, 09:03
Hey..
cool.. I have AIMer... i looked at your profile and saw you haev a AIMer SN... sgtsling

So.. hopefully i'll bump into you that way.. Thanks for the help!

-esoin

PS: my SN in AIMER is esoin

13 Mar 2001, 10:16
I changed the PHP file to this so far. Now I want to let him use this color: #333366 for the table backround and this color: #FF6600 as the boarder color. I donīt really know where and how to put. This is what I already modified:

13 Mar 2001, 16:01
Great Hack!
I'm attempting to customize it and I have two questions:

1. How can you automatically alternate the row colors that contain the subject heading?

2. Is there a way to use vb codes in popular.php such as <normalfont>, {tableheadbgcolor}, etc.?

Thanks

13 Mar 2001, 22:27
Works just fine :)

But how do I exclude private forums from this?

14 Mar 2001, 15:36
Guys i put this on my forum but i was wondering if there is a similar hack that shows the last 10 threads that have been replied to. I cant figure out how to do that.

regards,

~veedee

14 Mar 2001, 23:40
same here. I would like to know how to make it show the latest 10 post... thanks

-esoin

16 Mar 2001, 10:48
how do i make it appear on my forums?

this is what i put in my control panel for the

<!-- #include file="forums/toppost.php" -->
<!-- #include file="forums/popular.php" -->

27 Mar 2001, 01:31
has anyone figured out how to make it show the latest 10 post rather than top 10 popular post? thanks

-esoin

27 Mar 2001, 01:35
esoin, try this:

http://www.vbulletin.com/forum/showthread.php?threadid=12324

27 Mar 2001, 06:42
Much Thanks

-Esoin

27 Mar 2001, 19:06
Those interested in getting the last 10 posts... I would instead encourage to do this:

1. Open the header template. Look for the line which begins:<A HREF="usercp.php?s=$session[sessionhash]">
2. Insert the following line right before it:

<a href="search.php?s=&action=getdaily">Today's active threads</a><br>

Voila. Now your users have access to a preformatted page which lists all threads with posts from the last 24 hours. Works great on my site and looks like a built in feature, cause it is I suppose.

------------------------

Also, I didn't really expect so many variations that people would want for their site. I would highly recommend that you pick up a copy of mySQL by Paul DuBois, Michael Widenius. Just by reading the first few chapters you should be able to figure out how to change the query in the hack here to get it to do what you need.