Page 1 of 1

Echo picture from DB

Posted: Tue Jan 10, 2012 8:36 am
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?

Re: Echo picture from DB

Posted: Tue Jan 10, 2012 11:47 am
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}\" />";

Re: Echo picture from DB

Posted: Wed Jan 11, 2012 2:56 am
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.

Re: Echo picture from DB

Posted: Wed Jan 11, 2012 6:32 am
by twinedev

Code: Select all

echo '<td><img src="/images/' . $row['image_name'] . '" alt="Accesibiity Description" /></td>';

Re: Echo picture from DB

Posted: Wed Jan 11, 2012 7:35 am
by beljo
Thank you both, guys!
It helped me a lot.