vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   How do I get the total amount of replies? (https://vborg.vbsupport.ru/showthread.php?t=96033)

Boofo 09-11-2005 04:37 AM

How do I get the total amount of replies?
 
How can I chnage the following to get only the ammount of replies and not replies and threads?

PHP Code:

  $topposter $db->query_first("
  SELECT user.userid, user.username, COUNT(post.postid) AS postcount
  FROM " 
TABLE_PREFIX "post AS post
  LEFT JOIN " 
TABLE_PREFIX "thread AS thread ON (post.threadid = thread.threadid)
  LEFT JOIN " 
TABLE_PREFIX "user AS user ON (post.userid = user.userid)
  WHERE thread.forumid=
$forumid
  GROUP BY post.userid
  ORDER BY postcount DESC
  LIMIT 1
 "
); 


Andreas 09-11-2005 05:03 AM

Isn't that obvious? ;)

PHP Code:

$topposter $db->query_first("
  SELECT user.userid, user.username, COUNT(post.postid) AS postcount
  FROM " 
TABLE_PREFIX "post AS post
  LEFT JOIN " 
TABLE_PREFIX "thread AS thread ON (post.threadid = thread.threadid)
  LEFT JOIN " 
TABLE_PREFIX "user AS user ON (post.userid = user.userid)
  WHERE thread.forumid=
$forumid AND thread.firstpostid != post.postid
  GROUP BY post.userid
  ORDER BY postcount DESC
  LIMIT 1
 "
); 


Boofo 09-11-2005 05:27 AM

It wasn't until you pointed it out to me.

Thank you, sir. ;)

Boofo 09-11-2005 12:43 PM

Ok, new problem. ;)

The 2 following queries seem to be interfering with each other. What happens is the first query is only for the top replies to a thread. The second query is for all posts in a thread (Threads + Replies). Sometimes, not always, the Top Poster (second query) will pick up the Top Relpies (first query) username. The other counts seem to stay correct. First, is there a way to combine the 2 and if not, how do I keep the username mix-up from happening?

PHP Code:

 $topreplies $db->query_first("
SELECT user.userid, user.username, COUNT(post.postid) AS replycount
FROM " 
TABLE_PREFIX "post AS post
LEFT JOIN " 
TABLE_PREFIX "thread AS thread ON (post.threadid = thread.threadid)
LEFT JOIN " 
TABLE_PREFIX "user AS user ON (post.userid = user.userid)
WHERE thread.forumid=
$forumid AND thread.firstpostid != post.postid
GROUP BY post.userid
ORDER BY replycount DESC
LIMIT 1
"
);
 
$topposter $db->query_first("
SELECT user.userid, user.username, COUNT(post.postid) AS postcount
FROM " 
TABLE_PREFIX "post AS post
LEFT JOIN " 
TABLE_PREFIX "thread AS thread ON (post.threadid = thread.threadid)
LEFT JOIN " 
TABLE_PREFIX "user AS user ON (post.userid = user.userid)
WHERE thread.forumid=
$forumid
GROUP BY post.userid
ORDER BY postcount DESC
LIMIT 1
"
); 


Boofo 09-11-2005 01:12 PM

Ok, I think I fixed it. I changed the top poster query to this:

PHP Code:

  $topposter $db->query_first("
  SELECT user.userid, user.username, COUNT(post.postid) AS postcount
  FROM " 
TABLE_PREFIX "post AS post
  LEFT JOIN " 
TABLE_PREFIX "thread AS thread ON (post.threadid = thread.threadid)
  LEFT JOIN " 
TABLE_PREFIX "user AS user ON (post.userid = user.userid)
  WHERE thread.forumid=
$forumid AND thread.firstpostid = post.postid
  GROUP BY post.userid
  ORDER BY postcount DESC
  LIMIT 1
 "
); 

I added this:

PHP Code:

  AND thread.firstpostid post.postid 

to this:

PHP Code:

   WHERE thread.forumid=$forumid 

and it seemed to fix it. Still, is there a way to combine these 2 queries and get all the same info out of it?


All times are GMT. The time now is 04:59 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.01811 seconds
  • Memory Usage 1,733KB
  • 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
  • (6)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