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 03-23-2007, 05:31 AM
nathanrich nathanrich is offline
 
Join Date: Nov 2005
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Question about query results.

I have a plugin that queries the 7 most replied-to threads in the last 24 hours and displays it in a separate section of my forum. The query shown below works exactly as I want it to, grabbing all the threads in the last 24 hours, ordering them by replycount and grabbing the top 7.

PHP Code:
$twentyfouragotime() - (3600 24);

$popularquery="SELECT * FROM `thread` where `dateline` >= $twentyfourago ORDER BY `replycount` DESC LIMIT 7";
    
$merge=mysql_query($popularquery);
        echo 
mysql_error();

    while(
$popularrow=mysql_fetch_array($merge)){

$populardisplay .= "<b><a href='showthread.php?t=$popularrow[threadid]'>$popularrow[title]</a></b> <br />
<span class='smallfont'>&nbsp;     &nbsp;by 
<a href='http://www.nwfans.com/member.php?u=
$popularrow[postuserid]'>$popularrow[postusername] </a></span><br/>";


The threads are displayed with the most replied-to threads at the top and the 7th most replied-to at the bottom. What I'm wondering is how I can rearrange this so that it displays the threads by dateline with the oldest threads on top and the newest threads on the bottom. I would need to rearrange my query results after the query runs but before I display the results on the page.
Reply With Quote
  #2  
Old 03-24-2007, 03:55 PM
MarkPW MarkPW is offline
 
Join Date: Apr 2006
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
SELECT * FROM thread WHERE dateline >= $twentyfourago ORDER BY dateline ASC LIMIT 0,7
Reply With Quote
  #3  
Old 03-25-2007, 11:37 PM
nathanrich nathanrich is offline
 
Join Date: Nov 2005
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, but that's not what I was asking. I want the top 7 most replied-to posts, and my current query grabs those. What I want to know is how I can take those 7 posts after I've grabbed them and reorder them by dateline. Sorry if that wasn't clear.
Reply With Quote
  #4  
Old 03-25-2007, 11:46 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try using a sub-query like this,
PHP Code:
$twentyfouragoTIMENOW 86400;

$result $db->query_read("
    SELECT *
    FROM (
        SELECT *
        FROM " 
TABLE_PREFIX "thread
        WHERE dateline >= 
$twentyfourago
        ORDER BY replycount DESC
        LIMIT 7
    ) as sub_results
    ORDER BY dateline DESC
"
);

$populardisplay '';
while (
$thread $db->fetch_array($result))
{
    
$populardisplay .= "<b><a href=\"showthread.php?t=$thread[threadid]\">$thread[title]</a></b>
        <br /><span class='smallfont'>&nbsp;     &nbsp;by
        <a href=\"http://www.nwfans.com/member.php?u=
$thread[postuserid]\">$thread[postusername]</a> </span><br />";

Another idea is to do it in PHP using array sorting.
Reply With Quote
  #5  
Old 03-26-2007, 12:51 AM
nathanrich nathanrich is offline
 
Join Date: Nov 2005
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Perfect, thanks.
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 01:48 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.03595 seconds
  • Memory Usage 2,204KB
  • Queries Executed 11 (?)
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_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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_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