PDA

View Full Version : putting the first attachment in a variable


Sean S
02-09-2007, 05:59 AM
Hi there,

I'm trying to store the first attachment of the first post in a variable, but no matter what I do, I either get errors, or the showthread page stops loading.

basically this is the code that I have, but it doesn't work. I'm not really sure how I would store the first attachment of the firstpost in a variable,


global $vbulletin, $db;

# First Attachment of the First Post
$firstattach = $db->query_read("
SELECT a.attachmentid, a.dateline, a.postid, t.firstpostid
FROM " . TABLE_PREFIX . "attachment a
LEFT JOIN " . TABLE_PREFIX . "thread t ON t.firstpostid = a.postid
ORDER BY a.attachmentid DESC
LIMIT 1
");

while($row = $db->fetch_array($firstattach))
{

$attachdateline= $row['dateline'];
$attachid= $row['attachmentid'];

eval('$tested .= "' . fetch_template('tested') . '";');
}


Any sort of help would be appreciated,

thank you.

Analogpoint
02-09-2007, 04:11 PM
What are the errors you get? What are you trying to do with this?

Sean S
02-09-2007, 04:24 PM
What are the errors you get? What are you trying to do with this?

well the first couple of times, I got errors like "call to an undefined member function query_read" or errors mainly similar to that, but those errors went away after I set the globals.

Then I got no more errors, but the showthread page didn't load. All the other pages load up fine except showthread.

Basically what I'm trying to do is to have the first attachment of the first post stored in a variable so that I can call it within the template on the first post.

hope that makes sense, thanks.

Analogpoint
02-09-2007, 04:27 PM
Thanks, maybe I'm still not understanding... I need a coffee.. anyone want to do a starbucks run?

You mean like if the attachement is an image, you want to display it or something? Or if the attachement is a zip file you want the actual binary data of the zipfile in the variable?