Jump to content

Recommended Posts

Ok here goes this little experiment...

if (($coumadinEntry->inr >= 2) && ($coumadinEntry->inr <= 3)) {
$coumadinINR = $coumadinEntry->inr." It's Good";
}else{
$coumadinINR = $coumadinEntry->inr." Adjustment Needed";
}

this is located in a "foreach" building a table and although "It's Good" works reliably it now fills every box in that column with "Adjustment Needed" unless that column is between 2 and 3.

 

What I am wanting to happen is:

  • If between 2 and 3 it shows the level INR and "It's Good"
  • If below 2 it will show something else (likely "actual reading and an icon of some sort on each side of the number)
  • If above 3 it show something else (likely "actual reading and an icon of some sort on each side of the number)
  • if empty or NULL then it will set $coumadinINR=""; so nothing is displayed

 

Link to comment
https://forums.phpfreaks.com/topic/303970-a-php-if-between-two-numbers/
Share on other sites

if (($coumadinEntry->inr >= 2) && ($coumadinEntry->inr <= 3)) {
$coumadinINR = $coumadinEntry->inr." It's Good";
}elseif($coumadinEntry->inr < 2){
$coumadinINR = $coumadinEntry->inr." It's Low";
}elseif($coumadinEntry->inr > 3){
$coumadinINR = $coumadinEntry->inr." It's High";
}else{
$coumadinINR = "";
}

Ok so there is my hundredth attempt at this.

 

I know why its failing but I don't how to correct for it.  At this point because NULL is less than 2 it assumes that this is true and displays the "It's Low" with no value.

 

I thought this was the answer but I am missing something.  I

if (($coumadinEntry->inr >= 2) && ($coumadinEntry->inr <= 3)) {
$coumadinINR = $coumadinEntry->inr." It's Good";
}elseif($coumadinEntry->inr < 2) && ($coumadinEntry->inr != ''){
$coumadinINR = $coumadinEntry->inr." It's Low";
}elseif($coumadinEntry->inr > 3){
$coumadinINR = $coumadinEntry->inr." It's High";
}else{
$coumadinINR = "";
}

I think I am on the right track but its kicking me still...

if (($coumadinEntry->inr >= 2) && ($coumadinEntry->inr <= 3)) {
$coumadinINR = $coumadinEntry->inr." It's Good";
}elseif(is_null($coumadinEntry->inr)){
coumadinINR = "";
}elseif($coumadinEntry->inr < 2){
$coumadinINR = $coumadinEntry->inr." It's Low";
}elseif($coumadinEntry->inr > 3){
$coumadinINR = $coumadinEntry->inr." It's High";
}else{};

Edited by chadrt

oh my brain hurts now, us amateurs should be banned from any kind of code

if (($coumadinEntry->inr >= 2) && ($coumadinEntry->inr <= 3)) {
$coumadinINR = $coumadinEntry->inr." It's Good";
}

elseif(is_null($coumadinEntry->inr)){
$coumadinINR = "";
}

elseif($coumadinEntry->inr < 2){
$coumadinINR = $coumadinEntry->inr." It's Low";
}

elseif($coumadinEntry->inr > 3){
$coumadinINR = $coumadinEntry->inr." It's High";
}else{}

But alas its done and it works...  :D

if ($coumadinEntry->inr === null){
$coumadinINR = "";
} else if ($coumadinEntry->inr < 2){
$coumadinINR = $coumadinEntry->inr." It's Low";
} else if ($coumadinEntry->inr > 3){
$coumadinINR = $coumadinEntry->inr." It's High";
} else {
$coumadinINR = $coumadinEntry->inr." It's Good";
}
Start with your null condition so it doesn't get mixed up with the < 2 condition. Then check your less than or higher than conditions. If those all fail then it must be 2 or 3.
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.