Forum Moderators: coopster
<?php
$thread_result = mysql_query("SELECT * FROM thread ORDER BY dateline DESC LIMIT 0,25", $connection);
if (!$thread_result) {
die("Database query failed: " . mysql_error());
}
$attach_result = mysql_query("SELECT * FROM attachment", $connection);
if (!$attach_result) {
die("Database query failed: " . mysql_error());
}
while ($thread = mysql_fetch_array($thread_result)) {
if ($thread[22] != 0) {
while ($attach = mysql_fetch_array($attach_result)) {
if ($attach[9] == $thread[2]) {
echo "
<a href=\"showthread.php?t={$thread[0]}\">$thread[1]<br>
<img src=\"attachment.php?attachmentid={$attach[0]}\"></a><br>";
}
}
}
else {
echo "<a href=\"showthread.php?t={$thread[0]}\">$thread[1]<br>";
}
}
?>
Personally I would either read the threads into an array or do a single query with a JOIN.