Skip to main content
Inspiring
January 25, 2012
Answered

How do you replace one image with another

  • January 25, 2012
  • 1 reply
  • 849 views

I have a page that displays the results of a search for information about a club. One of the items is the club's logo. It is displayed using the following code

<img src="<?php echo $row_clubedit['club_logo_url']; ?>" alt="The Club's Logo"  class="logo" title="The Club's Logo">

This works fine, except when no club has been selected, in which case it shows the default question mark in a blue box.

It would be nice if I could display the Federation Logo, to which all the clubs belong, until a club is picked.

Is there a simple way to set a default image that would be replaced from a data set.

$row_clubedit['club_logo_url'] holds the url to the log in the format http://www.club.org/clublogo.png

<img src="<?php echo ( 'federation_logo_url'); ?>" alt="The Club's Logo"  class="logo" title="The Club'c Logo">

The logic I suppose would be

if club_logo_url does not exist,

          then print the  federation logo,

     else print the club logo.

How do you code that in php?

I'm only a beginner at PHP.

This topic has been closed for replies.
Correct answer

<img src="<?php echo $row_clubedit['club_logo_url'] == "" ? "http://www.club.org/clublogo.png" : $row_clubedit['club_logo_url']; ?>" alt="The Club's Logo"  class="logo" title="The Club's Logo">

should do it

1 reply

Correct answer
January 26, 2012

<img src="<?php echo $row_clubedit['club_logo_url'] == "" ? "http://www.club.org/clublogo.png" : $row_clubedit['club_logo_url']; ?>" alt="The Club's Logo"  class="logo" title="The Club's Logo">

should do it

Inspiring
January 26, 2012

That does indeed do the trick.

Many thanks

Howard Walker