samfletc
samfletc

Reputation: 11

Check if a range of numbers are within another range in PHP, or MySQL

It would have been ideal to do what I want to do in a MySQL query but I think I maybe quite limited after looking at BETWEEN.

So I've been looking at PHP...

So I have 2 numbers for a property size for example 200 - 3000

I then need to check if those 2 numbers and the range between them fall within another range, so in this example $sizemin = 500 and $sizemax = 1000

I've looked at the range() function but I can only seem to get it partially working.

Upvotes: 0

Views: 730

Answers (1)

RichardBernards
RichardBernards

Reputation: 3097

Uhm... with BETWEEN in MySQL:

SELECT num1, num2 FROM table WHERE (num1 BETWEEN num3 AND num4) AND (num2 BETWEEN num3 AND num4);

If you get a result from the query, the numbers are inside the range...

Upvotes: 1

Related Questions