Displaying image from database


Posted on 16th Feb 2014 07:03 pm by admin

Hi,

I've got a site where that's got a database behind it. Currently it has loads of items in rows that all have different pictures. There is a field called "Image" that has the name of the image ie. example.jpg.

Then I have a folder on my webserver called image where the pictures are stored with the same file names and extensions.

Now, I want to display the correct image for the item that the page is showing. I have this code but it's just showing the usual box with a red X in the top left.

I should also point out that the 'Item' line is working correctly and displaying the name of the item.

Quote<table border='1' align="left" width="100%">
<?php
while($row = mysql_fetch_array( $result )) {
$dir = '/image';
$image = $row['Image'];
echo('<b><h1>'.$row['Item'].'</h1></b><br />');

echo "<tr>";
echo "<td width=15%>"."<img width=100% src='$dir/$image /'></td>";
echo "<td width=85% align=center>Description</td>";
echo "</tr>";
}
?>
</table>
Any ideas why this isn't working?

No comments posted yet

Your Answer:

Login to answer
104 Like 35 Dislike
Previous forums Next forums
Other forums

Beginner PHP code help
Hi I'm new to php but if someone could please read the question below and help it would be great.

Easy administration on MySQL databases
My website is database driven and I am very tired of manually making queries to my tables in order t

Simple MySQL query...
Hello,
How could I do a mysql query that does this: SELECT * WHERE date/time < 5minutes ag

Email Processor
I have a few questions so this post will be a larger one! Sorry, but I'm a bit of a PHP newbie so be

Why use interfaces in PHP (OOP)
I am learning OOP in PHP and its been a pretty good learning experience so far. What I didn't unders

Snapshot from video
anyone knw how to make a snapshot maker from avi n mkv format.
for example if i give a direct lin

DATEDIFF Question
First time post, and of course it is a help question.

I am using a WP plug-in to display prev

Problem in String replace program's output
Hi all,
I was trying to make a program which accepts a string and replaces it with another stri

simple php table loop
Hi all,

I've the following code

<?php // Create category options

The type or namespace name 'ServiceModel' does not exist in the namespace 'System'
When I locally run the website, it works just fine, but when I uploaded it to the hosting environmen

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash