CodeIgniter Forums
Images on View Page - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Images on View Page (/showthread.php?tid=29958)



Images on View Page - El Forum - 04-27-2010

[eluser]01010011[/eluser]
Hi,

Using CodeIgniter, I am trying to place several images onto my view page as follows

Code:
...
<?php foreach($results_found as $item): ?>
<tr>
    <td>&lt;?php echo base_url();?&gt;images/$item->img.jpg</td>?
    <td>&lt;?php echo $item->title ?&gt;</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


Images on View Page - El Forum - 04-27-2010

[eluser]danmontgomery[/eluser]
$item->img is outside of php tags...

Code:
<td>&lt;img src="&lt;?php echo base_url().'images/'.$item->img.'.jpg'; ?&gt;"/&gt;</td>



Images on View Page - El Forum - 04-27-2010

[eluser]01010011[/eluser]
Thanks for your reply.

Unfortunately, all I get is a graphic and the outline of where the picture is supposed to be.
[quote author="noctrum" date="1272414623"]$item->img is outside of php tags...

Code:
<td>&lt;img src="&lt;?php echo base_url().'images/'.$item->img.'.jpg'; ?&gt;"/&gt;</td>
[/quote]


Images on View Page - El Forum - 04-27-2010

[eluser]danmontgomery[/eluser]
So copy the href tag from the source, past the url in your browser and see if you're getting a codeigniter 404 (codeigniter is routing your images, which indicates a problem with htaccess) or a regular 404 (the path is wrong)


Images on View Page - El Forum - 04-27-2010

[eluser]pickupman[/eluser]
If you are using the rewrite code from the user guide you need to add an exclusion for your images folder. The user guide code redirects all url's to index.php. Also, you may want to drop the http://.base_url() part for the src attribute. This creates additional http request for the browser to resolve.