Most commented entries SINCE [date]?
Posted: 07 May 2007 06:30 AM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  311
Joined  05-11-2004

Hi,

I want do display the most commented entries since a certain date (let’s say: most commented in the last 2 weeks). I think it needs only a little modification of the sql-query like shown in this thread, but i cannot do this. Would appreciate help very much - thanks in advance!

 Signature 

Der Lehrerfreund
Der Spamschlucker
Der Schweinische Bote

Profile
 
 
Posted: 07 May 2007 10:05 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  25625
Joined  05-20-2002

It depends- do you want it limited to ENTRIES made in the last 2 weeks- pull the ones with the most comments?  That’s pretty easy.  If you want a fresh count of the comments- counting only comments made in the last two weeks, that’s a fair bit more difficult.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 07 May 2007 11:34 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  311
Joined  05-11-2004

I thought about the second case: This entry has been commented 30x in the last 2 weeks (and so: 100x all in all). i am not so much into mysql, so i don’t know how complex to make this would be ...

 Signature 

Der Lehrerfreund
Der Spamschlucker
Der Schweinische Bote

Profile
 
 
Posted: 07 May 2007 03:29 PM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  759
Joined  08-16-2003

Toss this into a test template. Does it return the basically what you’re after? We can work on details later.

{exp:query sql="SELECT c.entry_id, c.comment_date, COUNT(c.entry_id) AS comment_count, t.title FROM exp_comments c, exp_weblog_titles t WHERE c.entry_id = t.entry_id
GROUP BY c.entry_id HAVING UNIX_TIMESTAMP() - c.comment_date <= (14*24*60*60) ORDER BY comment_count DESC, c.comment_date DESC LIMIT 100"
}
<p><strong>{title}</strong> - {comment_count} comment{if comment_count != 1}s{/if} in the last 14 days</p>
{/exp:query}

The query written more legibly:

SELECT c.entry_id, c.comment_date, COUNT(c.entry_id) AS count, t.title
FROM exp_comments c
, exp_weblog_titles t
WHERE c
.entry_id = t.entry_id
GROUP BY c
.entry_id
HAVING UNIX_TIMESTAMP
() - c.comment_date <= (14*24*60*60)
ORDER BY count DESC, c.comment_date DESC
LIMIT 100
Profile
 
 
Posted: 08 May 2007 12:48 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  311
Joined  05-11-2004

First: Thanks for your effort!

It seems to work basically, I implemented it here. But it doesn’t show properly the most-commented of the last 14 days.  In the right bar you can see the newest comments, there are for example some comments to this entry, which is in your hack not shown up.

 Signature 

Der Lehrerfreund
Der Spamschlucker
Der Schweinische Bote

Profile
 
 
Posted: 08 May 2007 09:50 AM   [ Ignore ]   [ # 5 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  25625
Joined  05-20-2002

I think the ‘having’ is only for summary variables?  Try it like:

SELECT c.entry_id, c.comment_date, COUNT(c.entry_id) AS count, t.title
FROM exp_comments c
, exp_weblog_titles t
WHERE c
.entry_id = t.entry_id AND UNIX_TIMESTAMP() - c.comment_date <= (14*24*60*60)
GROUP BY c.entry_id
ORDER BY count DESC
, c.comment_date DESC
LIMIT 100

Needs double checking though- group by still confuses me half the time.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 08 May 2007 11:12 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  311
Joined  05-11-2004

Ok, this works, thanks again! But I had to change something in your SQL-code, hell knows why: i had to use the variable “comment_count” instead of “count”. So the correct SQL-code is this:

SELECT c.entry_id, c.comment_date, COUNT(c.entry_id) AS comment_count, t.title
FROM exp_comments c
, exp_weblog_titles t
WHERE c
.entry_id = t.entry_id AND UNIX_TIMESTAMP() - c.comment_date <= (14*24*60*60)
GROUP BY c.entry_id
ORDER BY count DESC
, c.comment_date DESC
LIMIT 5

I am still wondering if I could display the titles as links to the entries. When I use the exp:weblog:entries-tag, I only get the newest entry. Is there any quick solution?

 Signature 

Der Lehrerfreund
Der Spamschlucker
Der Schweinische Bote

Profile
 
 
Posted: 08 May 2007 02:57 PM   [ Ignore ]   [ # 7 ]  
Grad Student
Rank
Total Posts:  40
Joined  04-06-2007

That seems like it should be simple.

What’s your code right now?  (Minus the query that you already have working)

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 03:47 PM
Total Registered Members: 120493 Total Logged-in Users: 51
Total Topics: 126564 Total Anonymous Users: 30
Total Replies: 665425 Total Guests: 295
Total Posts: 791989    
Members ( View Memberlist )