Jump to content

Displaying an Image in php via path in MYSQL


chimp

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:

[code]
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 );
[/code]

My php code is as follows:

[code]
<? $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++; } ?>
[/code]

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

http://uxellaleague.com/images/teams_200506/red_tile.jpg

but is displayed as follows

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

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?

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

Please Help

Thanks in advance
Andy
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.