Jump to content

Need help printing an image URL from a MySQL database


goodrichdesigns

Recommended Posts

I'm very new to using PHP and MySQL and I'm having real difficulty with some code. Here it is.

 

<?PHP

 

if ($player->avatar == '') {

echo "No avatar";

}

else {

print'<img src="'.$player['avatar'] .'" alt="'.$player['username'] .'">';

}

 

?>

 

 

 

(The current code just meses up my whole page)

 

Basically, I have a field in my database called avatar which is in the $player table. If there is an url within the field, I wish for that to be printed out in HTML as an image. If the field is blank, I want it to output as reading 'No avatar'.

 

Someone please help, I'm a programming noob in need of much wisdom from another! lol  ;D

Have you tried making the img tag self closing by adding a / before the >?

 

print'<img src="'.$player['avatar'] .'" alt="'.$player['username'] .'" />';

 

Depending on the browser and Document Type, this could be messing up the html rendering.

 

 

Hi thanks for the help however it still doesn't seem to work :(

 

 

print'<img src="'.$player->avatar .'" alt="'.$player['username'] .'">';

 

...doesn't work and neither does...

 

print'<img src="'.$player['avatar'] .'" alt="'.$player['username'] .'" />';

  • 2 weeks later...

Hi all, I'm still struggling with this script. It's for an assignment which is due in on Tuesday, can anyone pllleeease help?  :-[

 

<?PHP

if ($player->avatar == 0) echo "No avatar";

else print'<img src='.$player['avatar] .'" alt="'.$player['username'] .'">';

?>

 

 

The default value for the avatar field of my database is 0. If the value is 0 I want text to be outputted on the page reading 'No Avatar'. If there is something else e.g. an URL, I want this to be printed as an image on the page.

 

:)

Archived

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

×
×
  • 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.