views:

32

answers:

2
+1  Q: 

CodeIgniter Images

Hi,

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

+1  A: 

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>
Galen
+1 thanks for your reply Galen. The image is still not displaying, all that shows is a little square graphic
01010011
+1  A: 

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" />
Summer
+1. Thanks a lot Summer, it worked
01010011