if isset if...
Hi, I tried to figure this out but i'm shooting in the dark :)
What I want to do is compare two values, either value1 against value2 or if value2 is empty then value1 against value3. add to that, that I want to echo different images depending on the result.
<?php
if (isset($second)){
if($first - $second) <= 5){
echo "<img src=\"images/img1.png\" />";
}elseif($first - $second > 5){
echo "<img src=\"images/img2.png\" />";
}else{
echo "<img src=\"images/img3.png\" />";
}
}
else{
if($first - $third) <= 5){
echo "<img src=\"images/img1.png\" />";
}elseif($first - $third > 5){
echo "<img src=\"images/img2.png\" />";
}else{
echo "<img src=\"images/img3.png\" />";
}
}
?>
I don't know if I'm close or not in the ballpark, but hopefully someone else can help me make sense of this!
Take care
Adam
Related Article: Per day stock report
is a PHP discussion thread by anita_86 that has 2 replies and was last updated 1 year ago.
adishardis
Junior Poster in Training
91 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
I use similar
I dont think p will ever equal 3
<?php if(isset($second)){ $third == $second; }
if($first - $third) <= 5){$p='1';}
elseif($first - $third > 5){$p='2';}
else $p='3';
echo "<img src='images/img$p.png' />"; ?>
almostbob
Nearly a Senior Poster
3,282 posts since Jan 2009
Reputation Points: 585
Solved Threads: 399
Skill Endorsements: 7
If I paste this into my page the whole thing goes blank?! What could be the cause to that?
Otherwise the code looks great and thank you for taking time!
Peace
Adam
adishardis
Junior Poster in Training
91 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Thanks, I got all three images to show now thanks to your help!! :)
I altered your code to include abs to make it work with the last image:
<?php
if ($jamforelse == "")
{
if(abs($Er - $Er2) <= 5)
{
echo "<img src='img/no.png' />";
}
elseif($Er - $Er2 > 5)
{
echo "<img src='img/up.png' />";
}
else
{
echo "<img src='img/down.png' />";
}
}
else
{
if(abs($Er - $Se) <= 5)
{
echo "<img src='img/no.png' />";
}
elseif($Er - $Se > 5)
{
echo "<img src='img/up.png' />";
}
else
{
echo "<img src='img/down.png' />";
}
}
?>
So now it's working like a charm! :)
Thanks again
Adam
adishardis
Junior Poster in Training
91 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 9 Months Ago by
almostbob
and
Squidge