I'm using PHP and MySQL to display images on the first page.
When the image is clicked on I'm passing an ID to a new page.
I want that ID to display the ID data that's associated with that ID.
For example:
ID 1 should display - Title - title1, Details - details1, image - image1
and ID 2
ID 1 should dislay - Title - title2, Details - details2, image - image2
But only displaying ID 1 data not matter if the URL is - website.com/thedetials.php?id=1 or website.com/thedetials.php?id=2
In other words, it displays the same data even though the id in the URL is different.
Page 1
$sql="SELECT * FROM thetable";
$result = mysqli_query($con,$sql);
echo " <ul>";
while($row = mysqli_fetch_array($result) {
echo "<li'>";
echo "<a href='page2.php?id=$row[id]'><img src=$row[image]></a>";
echo "</li>";
}
echo "</ul>";
?>
<?php
// End while loop.
mysqli_close($con);
?>
Page 2
$id = $_GET['id'];
$sql="SELECT id, title, details, image, FROM thetable";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result);
?>
<?php echo $row['title'] ?>
<?php echo $row['details'] ?>
<img class='projectItem-pic' src="<?php echo $row['image']?>">
If I use below - No data displays, not sure why.
$sql="SELECT * FROM thetable WHERE id = $id";
Can someone tell me what I'm doing wrong?