Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-12-2003, 06:44 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Attachments per forum

Can anyone please tell what I am doing wrong or missing in this query? I am trying to get the attachments count per forum and right now it shows the same count and bytes in every forum. Here is the code:

PHP Code:
/** Count of Attachments Per Forum and Bytes **/
$attachs=$DB_site->query_first("SELECT forum.title AS forum, COUNT(attachment.attachmentid) AS count, SUM(LENGTH(attachment.filedata)) AS bytes
FROM attachment,post,thread,forum
WHERE attachment.attachmentid = post.attachmentid 
AND post.threadid=thread.threadid 
AND forum.forumid=thread.forumid
GROUP BY thread.forumid 
ORDER BY count DESC"
);

$attachs['count'] = number_format($attachs['count']);
$attachs['bytes'] = number_format($attachs['bytes']);
/** Count of Attachments Per Forum and Bytes **/ 
Reply With Quote
  #2  
Old 05-12-2003, 12:52 PM
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Location: Northampton, England
Posts: 6,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think your query is wrong...

I'm not sure if it is right, but try:

Code:
$attachs=$DB_site->query_first("SELECT forum.title AS forum, COUNT(attachment.attachmentid) AS count, SUM(LENGTH(attachment.filedata)) AS bytes
FROM attachment
LEFT JOIN post ON post.attachmentid=attachment.attachmentid,
LEFT JOIN thread ON thread.threadid=post.threadid,
LEFT JOIN forum ON forum.forumid=thread.forumid,
WHERE attachment.attachmentid = post.attachmentid 
AND post.threadid=thread.threadid 
AND forum.forumid=thread.forumid
GROUP BY thread.forumid 
ORDER BY count DESC");


Satan
Reply With Quote
  #3  
Old 05-12-2003, 01:08 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

After taking the commas out after the LEFT JOINs (gave db error), I get the same results that I was getting with the other code. It shows 51 attachments, which is what I have in one forum. It shows that one very forum.
Reply With Quote
  #4  
Old 05-13-2003, 03:16 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, we've narrowed it down to this:

SELECT SUM(attach) AS count FROM thread WHERE attach > 0 AND forumid=$forumid

Can anyone please tell me how to get the total filezise in both bytes and KB from this query?
Reply With Quote
  #5  
Old 05-13-2003, 03:17 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Looking into now.
Reply With Quote
  #6  
Old 05-13-2003, 03:18 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That was quick. Thank you, sir.
Reply With Quote
  #7  
Old 05-13-2003, 03:26 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I got it; however it takes 3.10 sec to execute. If you're going to use it I strongly suggest you make it cache itself daily or so.
[sql]
SELECT COUNT(p.postid), SUM(LENGTH(a.filedata)), f.title
FROM post p, thread t, forum f, attachment a
WHERE a.attachmentid = p.attachmentid AND t.threadid = p.threadid
AND f.forumid = t.forumid AND p.attachmentid > 0
GROUP BY f.forumid;
[/sql]
I'm sure it can be done with JOINs, too, but I don't know how.
Reply With Quote
  #8  
Old 05-13-2003, 03:27 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

BTW it's the SUM(LENGTH()) that's taking the most time. The query returns the number of posts with attachments, the cumulative filesize of all of those attachments, and the title of each forum, grouped by each forum.
Reply With Quote
  #9  
Old 05-13-2003, 03:36 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Using this shows the same attachments amount and file size in every forum.
Reply With Quote
  #10  
Old 05-13-2003, 03:48 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Didn't for me (MySQL 4.0.12). It returned distinct forum titles and the other stats for them
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 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.05210 seconds
  • Memory Usage 2,252KB
  • 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
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete