Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP "if" statement looking for between two numbers

I need help on a if statement here is what is going on.

I have a value being pulled $paint['product_id']

I need to say if that value is between 81501 - 81599 or 81701 - 81799 say blah

else if that value is between 81001 - 81099 or 81301 - 81399 say blah2

else if 86501 - 86599 or 86001 - 86099 or 85001 - 85099 say blah3

and say nothing if it does not apply.

What id did try

<? if ($paint['product_id'] >= 81501 && $x <= 81599 || $paint['product_id'] >= 81701 && $x <= 81799):?>
blah
<? elseif ($paint['product_id'] >= 81001 && $x <= 81099 || $paint['product_id'] >= 81301 && $x <= 81399):?>
blah2
<? elseif ($paint['product_id'] >= 86501 && $x <= 86599 || $paint['product_id'] >= 86001 && $x <= 86099 || $paint['product_id'] >= 85001 && $x <= 85099):?>
blah3
<? endif;?>

The problem I am having is "blah" is showing up on items in the blah3 category.

Hope that makes sense and thanks in advance for any help!

like image 605
user2465180 Avatar asked Dec 16 '22 09:12

user2465180


2 Answers

Replace $x with $paint['product_id'].

like image 89
mzedeler Avatar answered Jan 04 '23 22:01

mzedeler


You should group them with brackets:

if( ($x > 10 && $x < 20) || ($x > 40 && $x < 50) ) { ...
like image 35
Royal Bg Avatar answered Jan 04 '23 21:01

Royal Bg