The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
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:
|
#2
|
||||
|
||||
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 |
#3
|
||||
|
||||
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.
|
#4
|
||||
|
||||
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? |
#5
|
|||
|
|||
Looking into now.
|
#6
|
||||
|
||||
That was quick. Thank you, sir.
|
#7
|
|||
|
|||
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. |
#8
|
|||
|
|||
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.
|
#9
|
||||
|
||||
Using this shows the same attachments amount and file size in every forum.
|
#10
|
|||
|
|||
Didn't for me (MySQL 4.0.12). It returned distinct forum titles and the other stats for them
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|