Skip navigation
Currently Being Moderated

Dynamic image displays depending on yes / no value

Jan 11, 2011 4:39 AM

I've set up an ENUM column in my MySql database with a value of either 'y' (yes) or 'n' (no)

 

I have managed to display this record in a php webpage and even modified it to display a dynamic check box which is ticked if the value is 'y'

 

<input <?php if (!(strcmp($row_rsallJobs['sign_good_condition'],"y"))) {echo "checked=\"checked\"";} ?> type="checkbox" name="good_con" id="good_con" />

 

 

What I really want to do is display images depending on the value. For example 'yes.jpg' if the value is 'y' and 'no.jpg' if the value is 'n'.

 

How can I do this? Could I modify the code above?

 

 

Thanks!

 
Replies
  • Currently Being Moderated
    Jan 11, 2011 5:10 AM   in reply to Wookie

    Wookie wrote:

     

    What I really want to do is display images depending on the value. For example 'yes.jpg' if the value is 'y' and 'no.jpg' if the value is 'n'.

    Use a simple conditional statement:

     

    <img <?php if ($row_rsallJobs['sign_good_condition'] == "y") { 
      echo 'src="yes.jpg" alt="yes"';
    } else {
      echo 'src="no.jpg" alt="no"';
    } ?> height="20" width="20" />
     
    |
    Mark as:
  • Currently Being Moderated
    Jan 11, 2011 5:58 AM   in reply to Wookie

    Thanks. Glad to hear you're enjoying the book.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 17, 2011 11:58 AM   in reply to Wookie

    How could I expand this to 3 possible values? i.e.  - yes / no / maybe

    if/elseif/else

     

    if (value == "yes") {

    //show yes value

    } elseif (value == "no") {

    // show no value

    } else {

    // show value that doesn't = yes or no

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 18, 2011 7:10 AM   in reply to Wookie

    value$row_DetailRS1['photos_taken'] is not a variable, hence the error message.

     

    <?php if ($row_DetailRS1['photos_taken'] == "f") {
    print "full";
    } elseif ($row_DetailRS1['photos_taken'] == "p") {
    print "partial";
    } else {
    print "none";
    } ?>
     
    |
    Mark as:
  • Currently Being Moderated
    Sep 22, 2011 4:44 AM   in reply to Wookie

    ..sorry need some help.

     

    I can´t get it workin.....

     

    <img <?php $status="n";

    if ($status == "y") {

      echo 'src="stecker_on.png" alt="yes"';

    } else {

      echo 'src="stecker_off.png" alt="no"';

    } ?> height="71" width="101" />

     

    The image ist not showing... ideas ?

     

    All I get ist some text showing:

      height="71" width="101" />

     

     

     

    MANY THANKS !!!!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points