Echo array of images using codeigniter and mysql

I had GROUP_CONCAT in a MySQL database, so I created a view where the row of the image array is located. there he is:

in hotel_images column I have array of images

I use PHP CodeIgniter and I try to display these images on my page, but there are some problems: it displays only those images that are not in the array in the table row. here is my code to display:

<?php foreach ($get_hotels as $geth) { ?>

<td><img src="<?php echo base_url()."uploads/hotels/".trim(str_replace(",", " ", $geth->hotel_images));?>" width="73" height="53"></td>

<?php } ?> 

So my question is how to display images in the same one <td>as an array? any suggestions?

+4
source share
2 answers

You can try the following method:

<?php

foreach($get_hotels as $geth):
    $images = explode(',', $geth->hotel_images);
    foreach($images as $image): ?>
<td>
    <img src="<?= base_url() . "uploads/hotels/$image"; ?>" width="73" height="53">
</td>
    <?php
    endforeach; ?>

<?php
endforeach; ?>

, .

0

, :

$images = explode(',',$your query);
<?php foreach ($images as $key => $geth) { ?>

<td><img src="<?php echo base_url()."uploads/hotels/".$geth;?>" width="73" height="53"></td>

<?php } ?> 

, .

+2

Source: https://habr.com/ru/post/1688346/


All Articles