Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-26-2006, 02:57 PM
sebbe's Avatar
sebbe sebbe is offline
 
Join Date: Feb 2006
Location: .se
Posts: 195
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Get threads with most replies in last two weeks?

Ok I asked on vb.com but no one anwers there so I thought you guys know ho to go about this!?
____________________

I'm writing a script on a page outside of vb. I want it to print the 20 latest threads from a few specific forums that has got most replies in the last two weeks.
I'm currently in the learning state of MySQL and I think this could be a quite easy query for you pros.

Appreciate any effort to help, here's what I got so far

PHP Code:
$currentudate date("U");
$twoweeks $currentudate '1209600';
$query "SELECT title, postusername, threadid, postuserid, dateline, from_unixtime(dateline), forumid, replycount, views, from_unixtime(lastpost)
          FROM thread
          WHERE dateline >= 
$twoweeks
          ORDER BY replycount 
          DESC LIMIT 20"

I know this print the threads that were created in the last two weeks but as I said above, I want 20 threads which has got the most replies in the last two weeks.
Nvm I SELECT so many columns, I need them for something else.

Thanks!
Reply With Quote
  #2  
Old 02-26-2006, 08:50 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hmm this query should generally work:

[sql]
SELECT thread.*
FROM post
INNER JOIN thread USING (threadid)
WHERE thread.forumid IN (xx,yy,zz)
AND post.dateline >= $twoweeks
GROUP BY post.threadid
ORDER BY replycount DESC
LIMIT 20[/sql]
Reply With Quote
  #3  
Old 02-27-2006, 08:21 PM
sebbe's Avatar
sebbe sebbe is offline
 
Join Date: Feb 2006
Location: .se
Posts: 195
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks a lot for your help, it's almost what I want!

But when I use "ORDER BY replycount", the threads with VERY many posts show up in the top of the list, even though they haven't got the most new replies within the last two weeks.
It seems like threads (which has many replies) get onto this list that has only got a FEW new posts in the last two weeks but is put in the top because of their high replycount.
I hope you understand what I'm trying to say here!?

Again thanks for helping!
Reply With Quote
  #4  
Old 02-27-2006, 09:50 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ah, i see what you mean!

hmm, try that one instead:
[sql]SELECT count(post.postid) AS newpostcount, thread.*
FROM post
INNER JOIN thread USING (threadid)
WHERE thread.forumid IN (xx,yy,zz)
AND post.dateline >= $twoweeks
GROUP BY post.threadid
ORDER BY newpostcount DESC
LIMIT 20[/sql]
Reply With Quote
  #5  
Old 03-02-2006, 04:18 PM
sebbe's Avatar
sebbe sebbe is offline
 
Join Date: Feb 2006
Location: .se
Posts: 195
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Xenon, it works perfect.

Just on a side note, I'm also pulling out a line of text from the first post in each thread to display, I know how to do it but is there anyway to remove all words that begin with [ ? cause right now it looks like a mess if someone for example has written "[Font color=Blue]Hey this is my thread and I use this color for all the text[/font]". Also when the post is beginning with an image "[img]http://sjfiojdsifsopf.fsdfjsifjosdjfisdf.dfsd.gif[/ img]" this problem occurs.

Any help how to just remove the stuff inside of BB [] brackets would be greatly appreciated, I've tried numerous different ways but haven't come up with any that works!

Thanks again!

Nevermind, I figured it out myself!
Thanks for all help!
Reply With Quote
  #6  
Old 03-03-2006, 10:31 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

strip_bbcode? ^^
Reply With Quote
  #7  
Old 03-04-2006, 12:27 PM
sebbe's Avatar
sebbe sebbe is offline
 
Join Date: Feb 2006
Location: .se
Posts: 195
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I didn't even know there was a function called strip_bbcode, instead I used preg_replace("/\[.*?]/s", "", $firstpost).
It's good because it wont remove what's inside the bb codes, for example if someone writes something in bold, it's still there.
Reply With Quote
  #8  
Old 03-04-2006, 03:43 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

erm, isn't that what strip_bbcode is supposed to do?

don't mix it up with strip_quote
Reply With Quote
  #9  
Old 03-06-2006, 03:45 AM
sebbe's Avatar
sebbe sebbe is offline
 
Join Date: Feb 2006
Location: .se
Posts: 195
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ah I really dunno man, all I know is that it works as it should!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:55 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04283 seconds
  • Memory Usage 2,243KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete