I am trying to display an image from a function and then while loop. Image is not getting displayed. I have made the function in functions.php and called this file in config.php. Finally config.php is called in header.php file, means functions.php file is now accessable everywhere. Every other details is coming, just image is not getting displayed
my function
function get_featured_image($p_id) {
global $con;
// First, get the image_id from the products table
$featured_image_query = mysqli_query($con, "SELECT images_id FROM products WHERE id = $p_id");
$featured_image = mysqli_fetch_assoc($featured_image_query);
if ($featured_image) {
$image_id = $featured_image['images_id'];
// Next, fetch the image details from the images table based on the image_id
$image_query = mysqli_query($con, "SELECT * FROM images WHERE image_id = $image_id");
$image_data = mysqli_fetch_assoc($image_query);
if ($image_data) {
return $image_data['file_name'];
}
}
return ""; // Return an empty string if no featured image is found
}
My While Loop Where i want to display the image
<?php
$productscount = 0;
while ($products = mysqli_fetch_object($product_query)) {
$product_id = $products->id;
$featured_image = get_featured_image($product_id);
?>
<a href="product_details.php?id=<?php echo $products->id; ?>">
<img src="images/products/<?php echo $featured_image; ?>" class="img-fluid blur-up lazyload" alt="">
</a>
<?php } ?>
M