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

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

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.