PHP Code:
<?php
require('./admin/config.php');
//connect
$connection = mysql_connect("$servername","$dbusername","$dbpassword") or die ("Cannot connect to server.");
//select database
$db = mysql_select_db("$dbname", $connection) or die ("Could not select database.");
// create sql statement
$sql = "SELECT postid,post.threadid,post.title FROM post LEFT JOIN thread ON thread.threadid=post.threadid WHERE thread.forumid IN (22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38) AND thread.dateline=post.dateline AND post.attachmentid!=0 ORDER BY post.dateline DESC LIMIT 4";
//execute sql query
$sql_result = mysql_query($sql, $connection) or die ("Could not execute query.");
while ($row = mysql_fetch_array($sql_result)) {
list($postid,$threadid,$title)=$row;
echo "
<img src=\"http://www.pcreview.co.uk/attachment.php?postid=$postid\" border=\"0\">
";
}
mysql_free_result($sql_result);
mysql_close($connection);
?>
Changes I made: I put the echo command inside the while loop, so it will execute once for each row, instead of only once total;
I added getting titles and threadids and put those in their variables (be sure to stripslashes() on the title or it will have slashes in front of quotesigns);
I made sure the sql statement doesn't get posts that don't have attachments.