Jump to content


Displaying an Image in php via path in MYSQL

  • Please log in to reply
1 reply to this topic

#1 chimp

  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 05 July 2006 - 07:32 AM

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....06/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

#2 indalecio

  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 05 July 2006 - 07:44 AM

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:

<img src="<? echo $IMAGE_VARIABLE_LINK; ?>">

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.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users