vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Question about query results. (https://vborg.vbsupport.ru/showthread.php?t=142879)

nathanrich 03-23-2007 05:31 AM

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.

MarkPW 03-24-2007 03:55 PM

Code:

SELECT * FROM thread WHERE dateline >= $twentyfourago ORDER BY dateline ASC LIMIT 0,7

nathanrich 03-25-2007 11:37 PM

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.

Adrian Schneider 03-25-2007 11:46 PM

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.

nathanrich 03-26-2007 12:51 AM

Perfect, thanks. :)


All times are GMT. The time now is 05:50 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.01101 seconds
  • Memory Usage 1,730KB
  • 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_code_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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