vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Get threads with most replies in last two weeks? (https://vborg.vbsupport.ru/showthread.php?t=108939)

sebbe 02-26-2006 02:57 PM

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!? :cool:
____________________

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 :cool:

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!

Xenon 02-26-2006 08:50 PM

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]

sebbe 02-27-2006 08:21 PM

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!? :cool:

Again thanks for helping!

Xenon 02-27-2006 09:50 PM

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]

sebbe 03-02-2006 04:18 PM

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!

Xenon 03-03-2006 10:31 PM

strip_bbcode? ^^

sebbe 03-04-2006 12:27 PM

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. :)

Xenon 03-04-2006 03:43 PM

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

don't mix it up with strip_quote ;)

sebbe 03-06-2006 03:45 AM

Ah I really dunno man, all I know is that it works as it should! :)


All times are GMT. The time now is 11:07 AM.

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.01018 seconds
  • Memory Usage 1,729KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete