Home > OS >  Display the images stored in an array in php mysql
Display the images stored in an array in php mysql

Time:02-07

I am trying to display the images stored in an array.. I have stored the image name in the database enter image description here

I want to display the images which are stored in the database. Here is the code

<?php
if (isset($_REQUEST['id'])) {
    $id=$_REQUEST['id'];
    $result = ("select * from news where id='" . $_REQUEST['id'] . "'");
    $result1=mysqli_query($con,$result);
    if ($r = mysqli_fetch_array($result1,MYSQLI_ASSOC)) {
        $file=$r['file'];
?>
<?php
$images = explode(',', $file);
foreach($images as $file): ?>
    <td>
        <img src="uploads/<?php echo $r['file'] ?>" width="73" height="53">
    </td>
<?php
endforeach; 
?>

CodePudding user response:

In foreach you should print $file variable like below,

<img src="uploads/<?php echo $file; ?>" width="73" height="53">
  •  Tags:  
  • Related