Jump to content


This topic is now archived and is closed to further replies.


Displaying an Image in php via path in MYSQL

Recommended Posts

I am trying to display some data via php that i have stored in my mysql database,

I seem to have worked the code out for the text that i want displayed but when i enter the info for the photo that is stored in my mysql i just get the web link displayed instead of the actual image.

My Mysql database structure is as follows:

create table Players ( PlayerID integer not null primary key auto_increment , Forename varchar(50) , Surname varchar(50) not null , DOB date , RegNo tinyint , Photo varchar(255) , Nickname varchar(50) , Comments varchar(255) , Position varchar(50) , GamesPlayed tinyint , GoalsScored tinyint );

My php code is as follows:

<? $username="root"; $password=""; $database="players"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM players"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; $i=0; while ($i < $num) { $Forename=mysql_result($result,$i,"Forename"); $Surname=mysql_result($result,$i,"Surname"); $DOB=mysql_result($result,$i,"DOB"); $Nickname=mysql_result($result,$i,"Nickname"); $Photo=mysql_result($result,$i,"Photo"); echo "<b>$Forename$Surname</b><br>Date Of Birth: $DOB<br>Nickname: $Nickname<br>Photo: $Photo<br><br><hr><br>"; $i++; } ?>

the image is stored in the table under the field called Photo, it is stored as a url to the image as follows:


but is displayed as follows

Date Of Birth: 1971-04-08
Nickname: Gaffer
Photo: http://uxellaleague.com/images/teams_200506/red_tile.jpg

someone has said that this may help but i have no idea how to get it to work, should i leave the words std url in, for example?

$out .= "<img src=\".$prow['Std_URL'])."\" width=\"".$iSize['0']."\" height=\"".$iSize['1']."\" border=\"0\" alt=\"Select this for a more detailed image\">";

Please Help

Thanks in advance

Share this post

Link to post
Share on other sites
Your trying to get php to do too much for you with too little code.  The best solution for this, as I use this in my website, but in a different way is I get the image link stored in the database, then pull the link and put in the <img> tag.  Like so:

[code]<img src="<? echo $IMAGE_VARIABLE_LINK; ?>">[/code]

Don't try to add the image tags to php the way your doing, just manually add them and have php insert the link into the tag.  If people don't have a photo you can default to one if that input is empty.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.