Log in

View Full Version : Attachment SQL Query


MrD3SAi
03-02-2008, 04:49 AM
Currently I have a query to get the attachments for a specific post:
mysql_query("SELECT attachment.attachmentid AS attachmentid, covertype.type AS type FROM attachment LEFT JOIN covertype ON attachment.covertype = covertype.typeid WHERE attachment.postid = " . $threadinfo['firstpostid'] . " AND attachment.covertype != 0 ORDER BY attachment.covertype ASC") or die(mysql_error());
This works great; however, if I merge two posts and each post has attachment(s) it doesn't pull the attachment for the second post because
WHERE attachment.postid = " . $threadinfo['firstpostid'] .
Is there a way I can do a query based on all the post in the thread so it gets all the attachments for all the posts, not just the first one?

Boofo
03-02-2008, 04:55 AM
$threadinfo['postid'] maybe?

MrD3SAi
03-02-2008, 04:58 AM
UPDATE: I got it work using the following query:
mysql_query("SELECT attachment.attachmentid AS attachmentid, covertype.type AS type FROM attachment LEFT JOIN covertype ON attachment.covertype = covertype.typeid WHERE attachment.postid IN (SELECT postid FROM post WHERE threadid = " . $threadinfo['threadid'] . ") AND attachment.covertype != 0 ORDER BY attachment.covertype ASC") or die(mysql_error());

Boofo
03-02-2008, 05:00 AM
My answer was just a guess. A wrong one it seems now. ;)