Complex SQL Query Returns Wrong Info

I am having a problem with a query returning the proper results. My query is:


// BEGIN MAIN QUERY
$props = mysql_query("SELECT DISTINCT a.* FROM properties 
AS a INNER JOIN floorplans AS b 
ON b.PropID = a.PropID 
WHERE a.Active = '1' 
AND District LIKE '$School' 
AND Area LIKE '$Area' 
AND LargeDogs LIKE '$LargeDogs' 
AND Pets LIKE '$Pets' 
AND Size LIKE '$Size' 
AND Size LIKE '$BathSize' 
AND MoveInSpecial LIKE '$Movein' 
AND MML LIKE '$MML' 
AND Section8 LIKE '$Section8' 
AND ThreeML LIKE '$ThreeML' 
AND SixML LIKE '$SixML' 
AND NineML LIKE '$NineML' 
AND TwelveML LIKE '$TwelveML' 
AND OneCar LIKE '$Garage' 
AND Carport LIKE '$Carport' 
AND Underground LIKE '$Underground' 
AND OnBusLine LIKE '$OnBusLine' 
AND StackWDHook LIKE '$StackWDHook' 
AND FullWDHook LIKE '$FullWDHook' 
AND StackWDInst LIKE '$StackWDInst' 
AND FullWDInst LIKE '$FullWDInst' 
AND CeilingFans LIKE '$CeilingFans' 
AND Hardwood LIKE '$Hardwood' 
AND WalkinClosets LIKE '$WalkinClosets' 
AND WalkinShower LIKE '$WalkinShower' 
AND ComputerDesk LIKE '$ComputerDesk' 
AND Bookshelves LIKE '$Bookshelves' 
AND BalconyPatio LIKE '$BalconyPatio' 
AND Refrigerator LIKE '$Refrigerator' 
AND Icemaker LIKE '$Icemaker' 
AND Microwave LIKE '$Microwave' 
AND Dishwasher LIKE '$Dishwasher' 
AND Disposal LIKE '$Disposal' 
AND TrashCompactor LIKE '$TrashCompactor' 
AND TrashChutes LIKE '$TrashChutes' 
AND Pantry LIKE '$Pantry' 
AND CenterIsland LIKE '$CenterIsland' 
AND BreakfastBar LIKE '$BreakfastBar' 
AND ElcRange LIKE '$ElcRange' 
AND GasRange LIKE '$GasRange' 
AND WoodFP LIKE '$WoodFP' 
AND GasFP LIKE '$GasFP' 
AND WindowAC LIKE '$WindowAC' 
AND CentralAC LIKE '$CentralAC' 
AND GardenTub LIKE '$GardenTub' 
AND IndoorPool LIKE '$IndoorPool' 
AND OutdoorPool LIKE '$OutdoorPool' 
AND JacuzziSpa LIKE '$JacuzziSpa' 
AND Sauna LIKE '$Sauna' 
AND TanningBed LIKE '$TanningBed' 
AND Clubhouse LIKE '$Clubhouse' 
AND FitnessCenter LIKE '$FitnessCenter' 
AND Tennis LIKE '$Tennis' 
AND Basketball LIKE '$Basketball' 
AND Volleyball LIKE '$Volleyball' 
AND Racquetball LIKE '$Racquetball' 
AND SportsCourt LIKE '$SportsCourt' 
AND Billiards LIKE '$Billiards' 
AND Playground LIKE '$Playground' 
AND PicnicArea LIKE '$PicnicArea' 
AND BBQArea LIKE '$BBQArea' 
AND InternetCafe LIKE '$InternetCafe' 
AND BusinessCenter LIKE '$BusinessCenter' 
AND Price >= '$Price' 
AND MaxPrice <= '$MaxPrice' 
ORDER BY a.PropName ASC LIMIT $offset, $rowsPerPage");

I am getting returns that I should not be getting for the price range that I enter. I have a numeric value in my Price and MaxPrice fields as well.

Any help would be greatly appreciated. Everything seems to return correctly except the pricing information.

Can you show us the actual query with real values, instead of PHP variables?

This way we can make sure that the correct values are being passed to the query.

It’s also worth executing this query in phpMyAdmin (or whatever you use) and seeing what results MySQL returns.

what is the datatype of the price and maxprice columns? if VARCHAR, that would explain the wierd results

I can’t believe all these fields needs LIKE comparison.
Most of them looks like boolean.

Yep after I posted this realized they were in Varchar so I switched them to INT.

Seems to have cleared it up.

What would you suggest?

Equal operator
or even Greater than or equal operator
Because it is a search application and it should return rows with both PicnicArea present and absent if none were checked, I believe.