Hi im new to php and html. im trying to make a page for my first site where one can view all the comments posted on the site. these comments have image attachment. all the info is stored in a mysql database.
ive created a while loop to echo out every comment and image after each other. the text and the username gets updated correctly in each loop cycle but all the images are the same (the last picture loaded). i've been trying to figure it out but can't..
while($query_row = mysql_fetch_assoc($query_run))
{
$username = $query_row['username'];
$comment = $query_row['text'];
$id = $query_row['id'];
$image = $query_row['image'];
$_SESSION['comment_image'] = $image;
echo "Comment by <strong>$username</strong><br>";
echo $comment.'<br>';
echo '<img src=get_image.php><br>';
}
get_image.php:
session_start();
$image = $_SESSION['comment_image'];
header('Content-type: image/jpeg');
echo $image;
output:
Comment by USER1
text1
image3
Comment by USER2
text2
image3
Comment bu USER3
text3
image3
So the problem is that image3 gets echoed out on each comment when it should be image1 then image2 then image3, and so on. the image seems to be the one from the last comment shown.