Apologies for being frank, but your code is a mess, so it's difficult to help. Next time, please excise the relevant portion of the code, and include it directly in your post, between the forum's php tags (as I have done for you, below).
You are puzzled because more than one image is being output for each product. Correct? You have
try {
/*** connect to the database ***/
$dbh = new PDO("mysql:host=localhost;dbname=casa", 'root', 'root');
/*** set the PDO error mode to exception ***/
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/*** The sql statement ***/
$sql = "SELECT idProdCode, thumb_height, thumb_width, image_type, image_name FROM WickerOutdoor";
/*** prepare the sql ***/
$stmt = $dbh->prepare($sql);
/*** exceute the query ***/
$stmt->execute();
/*** set the fetch mode to associative array ***/
$stmt->setFetchMode(PDO::FETCH_ASSOC);
/*** set the header for the image ***/
foreach ($stmt->fetchAll() as $array) {
echo '<div> <p><a href="showfile1.php?idProdCode=' . $array['idProdCode'] . '"> <img src="showthumbs1.php?idProdCode=' . $array['idProdCode'] . '" alt="' . $array['image_name'] . ' /"> </a></p></div>';
}
}
catch (PDOException $e) {
echo $e->getMessage();
}
catch (Exception $e) {
echo $e->getMessage();
}
Look at your SQL query. Your problem has nothing to do with PHP. You are querying EVERY product photo each time you iterate over the above code. You need to qualify your SQL statement with a WHERE clause, e.g.:
$sql = "SELECT idProdCode, thumb_height, thumb_width, image_type, image_name FROM WickerOutdoor WHERE idProdCode = " . $row_Wicker_Data['idProdCode'];
Good luck!