user2567538
user2567538

Reputation: 15

storing and displaying image from database

I am trying to display an image trough php. I have the filepath of the image tsored in my table under 'imglink' but I can't display it with echo. Can you give me some suggestions on how exactly to do it? My code is below. Also when i'm soring the filepath does it need to be the full path C:.....etc or can it just be the folder with the images? Thank you

$sql = "SELECT `Name`, `Location`, `Description`, `Airport`, `imglink` FROM `attractions` WHERE `Category`='HistV'";

    $result = mysql_query($sql, $link);

    if (!$result) 
    {
        echo "DB Error, could not query the database\n";
        echo 'MySQL Error: ' . mysql_error();
        exit;
    }

    while ($row = mysql_fetch_assoc($result)) 
    {
        echo $row['Name'];
        echo "<img src=\"{$row['image']}\" />";
    }

Upvotes: 0

Views: 56

Answers (2)

Gadgetster
Gadgetster

Reputation: 483

If your 'image' is stored in the format name.jpg then what you are after is:

echo '<img src="'.$row['image'].'">';

Hope that helped!

Upvotes: 0

AR.
AR.

Reputation: 1955

You use 'image' in the result row, but in your query it's 'imglink'.

echo "<img src='" . $row['imglink'] . "'>";

should work as long as that row actually has proper path. To check whether the path is correct or not -simply print it out. The path should be relative to whatevere page you are calling it from.

Upvotes: 1

Related Questions