Jump to content


Photo

A PHP if () between two numbers


  • Please log in to reply
4 replies to this topic

#1 chadrt

chadrt
  • Members
  • PipPipPip
  • Not So Advanced Member
  • 123 posts
  • LocationSpokane Valley, WA
  • Age:38

Posted 20 May 2017 - 03:31 AM

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

 



#2 requinix

requinix
  • Administrators
  • Lazy Administrator
  • 9,374 posts
  • LocationWA

Posted 20 May 2017 - 03:35 AM

Okay... so... do that? You already seem to understand how comparisons work so write a couple more of them.
The Reimann Zeta Function Trolley Problem | "Summer is when I, the great ice fairy, can show my true power!"

#3 chadrt

chadrt
  • Members
  • PipPipPip
  • Not So Advanced Member
  • 123 posts
  • LocationSpokane Valley, WA
  • Age:38

Posted 20 May 2017 - 03:47 AM

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, 20 May 2017 - 03:57 AM.


#4 chadrt

chadrt
  • Members
  • PipPipPip
  • Not So Advanced Member
  • 123 posts
  • LocationSpokane Valley, WA
  • Age:38

Posted 20 May 2017 - 04:18 AM

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



#5 kicken

kicken
  • Gurus
  • Wiser? Not exactly.
  • 3,317 posts
  • LocationBonita, FL

Posted 20 May 2017 - 03:57 PM

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.
Did I help you out? Feeling generous? I accept tips via Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7
Kicken's World⦄ ⦃Recycle old CD's




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users