Reputation: 4050
Using CodeIgniter, I am trying to place several images onto my view page as follows
...
<?php foreach($results_found as $item): ?>
<tr>
<td><?php echo base_url();?>images/$item->img.jpg</td>?
<td><?php echo $item->title ?></td>
</tr>
...
but all this displays is the url for the images.
I've stored the names of the images in my database, hence my attempt to use $item->img to get access the name. The images are located in my root directory (htdocs\website_name\images)
Any help would be really appreciated. Thanks in advance
Upvotes: 1
Views: 1482
Reputation: 2498
You need an image tag. The CodeIgniter way to do it is:
<tr>
<td><img src="<?= base_url(); ?>images/<?= $item->img ?>.jpg" /></td>
<td><?php echo $item->title ?></td>
</tr>
Try it, and check View -> Source to make sure the syntax of the image element reads like this once its been rendered into html:
<img src="http://mysite.com/images/myimage.jpg" />
Upvotes: 2
Reputation: 30170
You need an image element!!! Im not sure what your $item object looks like but try this
<tr>
<td><img src="/images/<?php echo $item->img ?>.jpg"></td>
<td><?php echo $item->title ?></td>
</tr>
Upvotes: 1