Output an image if true. PHP help required!

Discussion in 'PHP' started by RJP1, Jul 30, 2008.

  1. #1
    Hi guys,

    The following code is used by my site to output "Yes" or "No" depending on if the listing is "featured". I think it normally displays "1" or "0" for yes and no, but the language bit converts the numbers to text (the _CMN_YES : _CMN_NO bit)

    Anyway, my question, how can I stop it from displaying the yes/no and instead of 1, display an image and if the value = 0 nothing is displayed?

    Thanks for you help! RJP1

    							elseif ($key == "featured") { 
    								if (!$caption[$key]->hideCaption) {
    									echo '<span class="hp_caption">'.$caption[$key]->caption."</span>: ";
    								}
    								echo $caption[$key]->prefix_text
    									.	( ($value == '1') ? _CMN_YES : _CMN_NO )
    									.	$caption[$key]->append_text
    									.	"<br />";
    							} // End if (featured)
    Code (markup):
     
    RJP1, Jul 30, 2008 IP
  2. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It seems your code is outputting html, so you cannot directyl output an image, but you can output an <img> tag pointing to the image.
     
    matthewrobertbell, Jul 30, 2008 IP
  3. payu

    payu Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3

    try this ...

    							elseif ($key == "featured") { 
    								if (!$caption[$key]->hideCaption) {
    									echo '<span class="hp_caption">'.$caption[$key]->caption."</span>: ";
    								}
    								echo $caption[$key]->prefix_text
    									.	( ($value == '1') ? '<img src="[COLOR="Red"]{your image here}[/COLOR]">' : '' )
    									.	$caption[$key]->append_text
    									.	"<br />";
    							} // End if (featured)
    Code (markup):
    you can also get rid of $caption[$key]->prefix_text and $caption[$key]->append_text if you don't need it.
     
    payu, Jul 30, 2008 IP
    RJP1 likes this.
  4. RJP1

    RJP1 Active Member

    Messages:
    345
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    Wow, thanks! This has been bugging me for ages! Cheers payu!
     
    RJP1, Jul 31, 2008 IP