PDA

View Full Version : Forumhome attachment query


squishi
10-05-2008, 10:39 AM
Hello,

I want to do a query in a plugin on the forumhome that is rather difficult for me to do.

I want to query the latest submitted attachment of 4 different forums (one attachment for each forum).

I had a look at the attachment database table, but there is of course no info in which forum the attachment was posted.

So the query would probably consist of several joins (qeurying the latest thread of a forum and then querying the latest attachment of that forum).

Can anybody help, please? :o

squishi
10-22-2008, 02:12 PM
How do I query the latest attachment in a certain forum, please?

squishi
11-30-2008, 09:11 AM
Bump. I'm still looking for a way to do this.

--------------- Added 1228043619 at 1228043619 ---------------

I guess the way to do this is find out the latest thread in a forum and then query the first attachment in this thread.
Should not be impossible. The forumhome shows info about the latest thread already...

bartek24m
01-23-2011, 03:19 PM
I'm also looking for a way to do this.

kh99
01-23-2011, 03:59 PM
Maybe something like this:

"SELECT attachmentid FROM " . TABLE_PREFIX . "attachment AS attachment
LEFT JOIN " . TABLE_PREFIX . "post AS post ON ( post.postid = attachment.postid )
LEFT JOIN " . TABLE_PREFIX . "thread AS thread ON ( thread.threadid = post.threadid )
WHERE thread.forumid IN ( 1, 2, 3 )
ORDER BY attachment.dateline DESC"


which finds attachment ids from forums 1, 2, or 3, newest ones first. I'm really just an SQL beginner so I don't know how you would do what the OP wants in one query. I suppose you could query all the attachments and read them until you find one from each forum, but i don't know how you'd do a query to return exactly one from each forum.