PHP - mysql行中的foreach循环

I am trying to generate dynamic images, I am using jquery to pass the id of the image from the mysql db to produce dynamic result , but it doesn't seems to working it only printing one image , my code is here

 <?php

 include 'conn.php';

 if (mysqli_connect_errno()) {
 printf("Connect failed: %s
", mysqli_connect_error());
 exit();
}

 $query = "SELECT id FROM homebg";
 $result = mysqli_query($conn, $query);
 if ($result->num_rows > 0) {

 while($row = $result->fetch_assoc()) {
 foreach ($row as $value) {
        echo " 
        <img class=\"responsive-img col l3\" id=\"img\">
        <script>  
$('#img').attr(\"src\",\"getImageadmin.php?id=\"+".$value.");
$('#img').show();
</script> ";
    }
  }
}
mysqli_close($conn);
?>  

Here I want to pass the value(id) of the image to the jquery used one by one , in each iteration so that it can print images one by one next to each other

Your $row is a array with all fields selected in your query (here is just id). So you need to do this :

while($row = $result->fetch_assoc()) {
    echo "<img class=\"responsive-img col l3\" id=\"img\">
    <script>  
    $('#img').attr(\"src\",\"getImageadmin.php?id=\"+".$row['id'].");
    $('#img').show();
    </script> ";
}
while($row = $result->fetch_assoc()) {
 foreach ($row as $value): ?> 
        <img class="responsive-img col l3" class="img" src = getImageadmin.php?id=<?php $value ?>>;
<?php endforeach; } ?>

You don't even need to use javascript/jquery. This solves the purpose. If you still need to use jQuery then use append() dont make ids because they're unique.