Hi im fairly new to php and I am making a website which should display lots of thumbnails of images on the main page. When a thumbnail is clicked on, the image appears in large on a new page. However at the moment only 1 thumbnail is displaying (of the latest uploaded image), and instead of the second thumbnail the image name is displayed as a hyperlink which ALSO opens up the same image as the first thumbnail! The remaining 8 images do not work and only their name appears as plain text. Here is my code.
<?php
include('./header.html');
require_once ('dbconnection.php');
$query = "SELECT * FROM image ORDER BY dateadded DESC LIMIT 10";
$result=mysql_query($query);
while($row=mysql_fetch_array($result, MYSQL_ASSOC))
{
$im = @imagecreatefromjpeg($row['imagepath']);
if($im) {
$width = imagesx($im);
$height = imagesy($im);
$scale = min( 150 / $width, 150 / $height);
$newwidth = $width $scale;
$newheight =$height $scale;
$im2 = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($im2, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($im2, "thumbnails/" . $row['imagepath']);
echo "<a href=\"view_photo.php?imageid={$row['imageid']}\"/>";
echo '<img src="thumbnails/'.$row['imagepath'].'"/><br />';
}
while($row = mysql_fetch_array($result))
{
//echo $row['imageid'] . " " . $row['imagename'];
echo "{$row['imagename']}</a>";
echo "<br />";
}
mysql_close($connection);
}
include('./footer.html');
?>
Please can someone tell me what i am doing wrong, and how i can fix this problem i am having. Thank you in advance.