How to call a image name from my database

#1
[eluser]Miguel Diaz[/eluser]
Hello

I´m a designer and I am starting to use a little of php on my web pages and also start with codeigniter just like 2 weeks ago. Can somebody help me letting me know how to call and image from my graphic folder to a query. Here is the code I have in this moment but it is not working.

Example:


<?php foreach($query->result() as $row): ?>
<strong>&lt;?=anchor('articles/view/'.$row->url, $row->title);?&gt;</strong>
<span>&lt;?=$row->date?&gt;</span>
<img >url, $row->graphics);?&gt; src="&lt;?=$row->date?&gt;" alt="titletags" />
<p>&lt;?=$row->shortdescription?&gt;&lt;?=anchor('articles/'.$row->url, 'read more');?&gt;</p>
&lt;?php endforeach; ?&gt;

The names of my data base titles are id, title, date, shortdescription and graphics.


This is the query I made if I take out the img tag it work perfect with the text but I would like to know how to do it with an image. I have one filed in my database with the name of the image and also with the extension and then I am trying to insert the text from the database to load the image.

Can somebody help me please.

#2
[eluser]CroNiX[/eluser]
nevermind, sorry the forum keeps eating the code Im posting

#3
[eluser]Alur[/eluser]
Hello Miguel,

You should place the image name (retrieved from the database) within an HTML image tag. The code should be something like:

Code:
<img src="&lt;?=$row['graphics']?&gt;" />

Don't forget to add the path to your graphics folder before the image name if necessary...

#4
[eluser]BrianDHall[/eluser]
And if you like the HTML Helper you can use
Code:
&lt;?= img($row['graphics']) ?&gt;

You just have to make sure the graphics you are referring to are pathed relative to the 'front controller' (index.php) of the website, otherwise you'll be pointing to the wrong places.

#5
[eluser]jedd[/eluser]
Hi Miguel and welcome to the CI forums.

I think the img() tags stuff is sorted, so I'll just chime in with the suggestion that you may find it clearer to not drop in and out of PHP/HTML so rapidly. You can code the above segment like this instead, for example:


Code:
&lt;?php
    foreach($query->result() as $row)  {
         echo "<strong>". anchor('articles/view/'.$row->url, $row->title) . "</strong>";
         echo "<span>". $row->date. "</span>";
         echo img($row['graphics']);  // You can put your extra tags into an array for img()
         }
?&gt;

Read more about the img() tag in the [url="/user_guide/helpers/html_helper.html"]HTML Helper[/url] section of the manual.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.