and the code below not tested it's just for to show u an example.
if i understand you correctly, you neeed two php pages.
1. index.php - use for fetch all the images links in the page
index.php
$query = "select * from tbl_image;
$stmt = $dbo->query($query);
while($row = $stmt->fetchAll(PDO::FETCH_ASSOC) {
echo "<a href=/display.php?id=" . $row['id'] . ">" . $row['name'] . "</a>"
}
2. you need display page to show image that user clicked.
display.php
$id = $_GET['id'];
$query = "select * from tbl_image where id=:id";
$stmt = $dbo->prepare($query);
$stmt->bindParam(":id", $id);
$stmt->execute();
while($row = $stmt->fetchAll(PDO::FETCH_ASSOC) {
}