well, to be exactly, it's not a real loop, as you are limiting the ammount of results to 1.
still that code would look better then:
PHP Code:
// Thumbnails
if($foruminfo['forumid'] == 22 AND $getpostid = $DB_site->query_first("
SELECT postid from post WHERE threadid = $thread[threadid] LIMIT 1"))
{
$attachment = $DB_site->query_first("
SELECT filename, attachmentid, IF(thumbnail_filesize > 0, 1, 0) AS hasthumbnail
FROM " . TABLE_PREFIX . "attachment
WHERE postid = $getpostid[postid]
ORDER BY rand() LIMIT 1
");
$attachmentid = $attachment['attachmentid'];
$hasthumbnail = $attachment['hasthumbnail'];
}
// Thumbnails