MySql Select Statement Problem
Posted 19 September 2006 - 10:45 AM
I have a problem with my SQL query, firstly variables below all equal;
$make = Audi
$model = TT
$mileagelow = 500
$mileagehigh = 70000
$pricelow = 1000
$pricehigh = 20000
The SQL statement is shown below;
$query = "select * from car, cardetails, comments where car.make like '$make' and car.model like '$model'
and car.mileage >= ‘$mileagelow’ and car.mileage <= ‘$mileagehigh’
and car.price >= ‘$pricelow’ and car.price <= ‘$pricehigh’ ";
It can find a car without the mileage and price parameters, however when I include the last 2 lines, it can’t find any cars. The mileage and price variables are being posted from a Select Drop Box in a search page and the make and model variables are also being posted using a Select Drop Box. Not sure what the problem is with those two lines, any help would be much appreciated.
Posted 19 September 2006 - 11:15 AM
Could it be there is not data in table meeting those criteria?
BTW, you could also use
... and car.mileage BETWEEN ‘$mileagelow’ AND ‘$mileagehigh’
and car.price BETWEEN ‘$pricelow’ AND ‘$pricehigh’ ";
Donations gratefully received
|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
Posted 19 September 2006 - 11:21 AM
SELECT * FROM car LEFT JOIN cardetails ON car.fieldname = cardetails.fieldname LEFT JOIN comments ON car.fieldname = comments.fieldname WHERE car.make like '$make' AND car.model LIKE '$model'
AND car.mileage >= ‘$mileagelow’ AND car.mileage <= ‘$mileagehigh’
AND car.price >= ‘$pricelow’ AND car.price <= ‘$pricehigh’ ";
Now the fieldname I put in, needs to be the connector, to connect them together,
Posted 19 September 2006 - 05:31 PM
Also thanks Barnard for the BETWEEN tip, it's much more elegant to put it that way rather than car.price >= $price and car. price etc etc etc
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users