Jump to content

How do I output an image if a value = 1?


RJP1

Recommended Posts

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

<?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.

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)
?>

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.