Page 1 of 1
MySQL: how do you query a price range?? min - max
Posted: Fri Aug 14, 2009 2:48 pm
by simonmlewis
Code: Select all
$result = mysql_query ("SELECT * FROM dxvehicles WHERE make = '$make' AND title LIKE '%$model%' AND motability = '$motability' AND stockstatus = 'in stock' AND scrappage != 'scrappage' LIMIT $offset, $rowsPerPage") or die (mysql_error());
Here's the code.
I am also passing pricemin and pricemax through to this page. So basically I need to do something like this:
Code: Select all
SELECT * FROM dxvehicles WHERE price <= pricemax AND price >= pricemin
Is there such a query?
I have only ever done this in an IF statement after the query, but am sure there is a 'query' way of doing it.
Re: MySQL: how do you query a price range?? min - max
Posted: Fri Aug 14, 2009 3:27 pm
by Eran
Did you try and run this query? it should work, so I'm not seeing the problem here.
Re: MySQL: how do you query a price range?? min - max
Posted: Fri Aug 14, 2009 3:30 pm
by jackpf
You could use
between. It shouldn't make any difference....but it'll make the query more readable.
Re: MySQL: how do you query a price range?? min - max
Posted: Fri Aug 14, 2009 4:18 pm
by simonmlewis
I've made the <= work well.
Is 'between' a better way to code it? How do you write that?
Re: MySQL: how do you query a price range?? min - max
Posted: Fri Aug 14, 2009 4:20 pm
by Eran