RJP1 Posted July 30, 2008 Share Posted July 30, 2008 Hi guys, First post! Anyway, I have a script that displays "Yes" or "No" depending on if a listing is featured or not. My question is how do I change the following code to show an image if the value = 1 (Yes) and nothing if it = 0 (No)? Thanks for any help you may have. 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) The "_CMN_YES : _CMN_NO" bit is language file based and fetches "Yes" or "No" from another file if you were wondering! RJP1 Link to comment https://forums.phpfreaks.com/topic/117400-how-do-i-output-an-image-if-a-value-1/ Share on other sites More sharing options...
dubc07 Posted July 30, 2008 Share Posted July 30, 2008 <?php 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 />"; if ($value =1); { echo 'html image code would go here'; } echo 'value does not = 1'; } // End if (featured) ?> Hope this helps. Link to comment https://forums.phpfreaks.com/topic/117400-how-do-i-output-an-image-if-a-value-1/#findComment-603892 Share on other sites More sharing options...
RJP1 Posted July 30, 2008 Author Share Posted July 30, 2008 Er, that helps a bit. But How do I get it to only show if the value does = 1 and not on all? Also, how do I remove the language bit? Cheers for your help! RJP1 Link to comment https://forums.phpfreaks.com/topic/117400-how-do-i-output-an-image-if-a-value-1/#findComment-603937 Share on other sites More sharing options...
dubc07 Posted July 30, 2008 Share Posted July 30, 2008 Try this. I came up with an error on elseif so i removed it and the language bit. If you have something setting the value put it into a variable and place it inside ( ($value == '$here')) . Otherwise post more of the program so we can see the thing in action. <?php if ($key == "featured") { if (!$caption[$key]->hideCaption) { echo '<span class="hp_caption">'.$caption[$key]->caption."</span>: "; } echo $caption[$key]->prefix_text . ( ($value == '1')) . $caption[$key]->append_text . "<br />"; if ($value =1); { echo 'html image code would go here'; } echo 'value does not = 1'; } // End if (featured) ?> Link to comment https://forums.phpfreaks.com/topic/117400-how-do-i-output-an-image-if-a-value-1/#findComment-603955 Share on other sites More sharing options...
RJP1 Posted July 30, 2008 Author Share Posted July 30, 2008 Hmm, nope if shows regardless of if it is featured or not... any ideas? Thanks for your help by the way, really appreciated. RJP1 Link to comment https://forums.phpfreaks.com/topic/117400-how-do-i-output-an-image-if-a-value-1/#findComment-603965 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.