We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,280 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

3
Contributors
4
Replies
3 Hours
Discussion Span
9 Months Ago
Last Updated
5
Views
Question
Answered
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
<?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 :)

Squidge
Posting Pro in Training
413 posts since Dec 2009
Reputation Points: 111
Solved Threads: 62
Skill Endorsements: 5

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

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0715 seconds using 2.76MB