0

I have the following code

<figure>
<?php if ($data[$i]->thumbnail) { ?>
  <img src="<?php echo $img ?>" width="465" height="300" alt="news-report-juli19" title="" />
<?php } ?>
</figure>

I want to display images from mysql database dynamically, the image_field_name=thumbnail. I have 10 records in db and all have different images.

Vickel
  • 7,879
  • 6
  • 35
  • 56
mukesh
  • 19
  • 1
  • 7

3 Answers3

0

use query variale with db colmn where images are present

use this in source img src

echo $query_variable['db_coln_name'] 
0

You should have to given the image path as well when you want to display.

<?php if ($data[$i]->thumbnail) { ?>
  <img src="<?php echo base_url('path_of_img/$img'); ?>" width="465" height="300" alt="news-report-juli19" title="" />
<?php } ?>
Anand Pandey
  • 2,025
  • 3
  • 20
  • 39
0

If you use the Codeigniter framework, please try this. In controller

$data['images'] = $this->model->get_images();
$this->load->view('view_name', $data);

In model you should make get_images() method that get image urls.

In view

<?php
    foreach ($images as $value) {
       echo '<img src="'.$value['thumbnail'].'" width="465" 
               height="300" alt="news-report-juli19" title="" />';
    }
?>

Good luck.

Happy Son
  • 81
  • 4