I have got a database called usermovie where i have stored info about movie (like name, genre, pic, title, fav, etc). When i tried to echo movie pics which are user favourite using currently logged in user id as condition it displays all images perfectly in php page but when i tried to use session variable and echo it in div tag it shows only one pic why is that happening can ayone help me with this ?
my code
usermovie.php
<?php
require_once 'db.php';
$id = $_SESSION['id'];
$moviefav = "Yes";
$query = "SELECT movie_pic FROM usermovie WHERE id=? AND movie_fav=?";
$stmt = $conn->prepare($query);
$stmt->bind_param('is', $id, $moviefav);
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()) {
echo "<img src=" . $row['movie_pic'] . ">";
$usermovieFav = "<img src=" . $row['movie_pic'] . ">"
$_SESSION['usermovieFav'] = $usermovieFav;
}
?>
I have stored five movies and selected all five movies as fav above code perfectly displays all five pics when i open usermovie.php but when i use the above session variable and try to echo it in div tag it only shows one pic which is stored last in database why is that happening i want to display all five pics in index.php
index.php
<div>
<?php echo $_SESSION['usermovieFav']; ?>
</div>
Thank you