Forum Moderators: coopster

Message Too Old, No Replies

image link from database help

noob, image, sql

         

joeyweaver

3:27 pm on Apr 30, 2008 (gmt 0)

10+ Year Member



I am very new to PHP (today!) and I'm trying to display an image from a link in a database. My code is currently:

<?php
mysql_connect ("localhost", "name", "pw");
mysql_select_db (accomplishments);
$sql = "SELECT * FROM `users`";
$query = mysql_query($sql);

while ($row = mysql_fetch_array($query)) {
echo "<p>",$row['first_name']," ",$row['last_name']," ", $row['acc1'];
}
?>

If I put <img src="1.gif"> in the database for acc1 the image will display. I want to be able to just put 1 or 1.gif in the database and still have it show. I've seen some examples of people putting the html code within the php, but I can't get it to work.

Any help would be greatly appreciated!

Pico_Train

4:03 pm on Apr 30, 2008 (gmt 0)

10+ Year Member



Try this:

echo "<p>".$row['first_name'].", ".$row['last_name'].", ".$row['acc1']."<img src='".$row['image']."'></p>";

I moved some of your commas around too...that should work. $row['image'] being the filename stored in the DB as 1.gif

[edited by: Pico_Train at 4:05 pm (utc) on April 30, 2008]