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
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..

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.