0

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

3
Contributors
4
Replies
7
Views
5 Years
Discussion Span
Last Post by adishardis
1

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' />";  ?> 

Edited by almostbob

0

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

1
<?php

    if ($second == "")
    {
        if($first - $third <= 5)
        {
            echo "<img src='images/img1.png' />";
        }
        else 
        {
            echo "<img src='images/img3.png' />";
        }
    }
    else
    {
        if($first - $second <= 5)
        {
            echo "<img src='images/img1.png' />";
        }
        else
        {
            echo "<img src='images/img2.png' />";
        }
    }

?>

Img 3 will never show as they way you have your logic <=5 & >5 what else is there?

It will be greater or less than or equal to :)

Edited by Squidge

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.