Jump to content

if data is between "then echo"


jacko_162

Recommended Posts

i have a set of values that i echo on a page;

 

$test1, $test2, $test3 etc etc..

 

i want an if statement to show if the said value is between X and y show blueicon.png else show redicon.png

 

i have been googling syntax but to no avail.

 

this is my current code snippet;

<?php echo $test1 ?> <? if ($test1 < 1.025)
echo "show blue icon.png"; ?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/194777-if-data-is-between-then-echo/
Share on other sites

You could use something along the lines of:

 

if ($test1 > $x && $test1 < $y) {
    echo '<img src="blueicon.jpg" />';
} else {
    echo '<img src="redicon.jpg" />';
}

 

However for something like this you may be better off using the ternary operator (scroll down to example 2):

 

<img src="<?php echo ($test1 > $x && $test1 < $y) ? 'blueicon.jpg' : 'redicon.jpg'; ?>" />

 

Edit: not sure given your original description and Wolphie's reply, which numbers you want to compare..

 

Me either really, I just took a shot in the dark.

 

each statement will have the numbers entered manually.

 

for instance;

 

IF $test1 = is between 1.020 & 1.027 = show blueicon.png
else show redicon.png

 

hope this clears it up, tbh i could have these set values in the database but for now i need them in the code.

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.