Echo picture from DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
beljo
Forum Newbie
Posts: 3
Joined: Tue Jan 10, 2012 8:31 am

Echo picture from DB

Post by beljo »

Hey!

Im a newbie and I need some help.
Im making a website that inserts data into database and then I want to echo it.

There is 3 forms: Topic, text, and picture.
The picture goes to servers folder and image_name into DB what is uniqid();

So how I echo the pictures?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Echo picture from DB

Post by Celauran »

Grab the path in your query, then stick it in an <img> tag.

Code: Select all

$query = "SELECT image_path
          FROM table_name
          WHERE something = 'whatever'";
$result = $sql->query($query)->fetch(PDO::FETCH_OBJ);

echo "<img src=\"{$result->image_path}\" />";
beljo
Forum Newbie
Posts: 3
Joined: Tue Jan 10, 2012 8:31 am

Re: Echo picture from DB

Post by beljo »

Hi! TY for answering.

I really didn't get it what I need to do.
Now I got these codelines:

$result = mysql_query("SELECT Pealkiri, Sisu, image_name FROM Portfoolio");

echo"<table border='1'>
<tr>
<th>Pealkiri</th>
<th>Sisu</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo"<tr>";
echo "<td>".$row['Pealkiri']."</td>";
echo "<td>".$row['Sisu']."</td>";
echo"</tr>";
}
echo "</table>";
mysql_close($link);

// "Pealkiri" is the topic and "Sisu" is the text. Image name is "$image_name=uniqid().'.'.$extension;"
and images are uploaded to "/images" folder

Can somebody explain it to noob how it's done.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Echo picture from DB

Post by twinedev »

Code: Select all

echo '<td><img src="/images/' . $row['image_name'] . '" alt="Accesibiity Description" /></td>';
beljo
Forum Newbie
Posts: 3
Joined: Tue Jan 10, 2012 8:31 am

Re: Echo picture from DB

Post by beljo »

Thank you both, guys!
It helped me a lot.
Post Reply