foreach loop in database table column with multiple images

1.6k views Asked by At
<?php  
    $images= $uploading['front_image'];
    $whileimg= explode(",", $images);
    foreach ($whileimg as $key => $image) {
        echo  $uploading["front_image"];          
    }
?>

In database I have my images saved in one column(2,3,4 it depends). now when I want them all to show in web ,Instead of images I get the path of the photos, as are saved in database. thank you

3

There are 3 answers

1
Ravinder Reddy On

To display images, you have use img tag

foreach ($whileimg as $key => $image) {
        echo  "<img src='".$image."' alt='image'>";   
    }
1
clearshot66 On

You need to make it an image take and echo the path in the img is what it sounds like you're getting:

 echo "<img src='".$image."' /> 

instead of

echo  $uploading["front_image"];   

So:

<?php  
    $images= $uploading['front_image'];
    $whileimg= explode(",", $images);
    foreach ($whileimg as $key => $image) {
        echo "<img src='".$image."' />          
    }
?>
0
Deepansh Sachdeva On

Assuming you are fetching comma separated paths of images using the following line:

$images= $uploading['front_image'];

You just need to use the following loop after creating array of paths:

foreach ($whileimg as $key => $image) {
    echo "<img src='$image'>";
}