darknessmdk Posted March 15, 2007 Share Posted March 15, 2007 So I'm making a search that looks for houses that are between two prices set by the user, one is a minimum price and the other one the max price. there is only one price in my database right now and its 269,000 I get results returned only when the minimum price is 100,000 and the max is 999,999, if the max price goes up or the min price goes down it doesnt work. Here's the code, Its my first time searching with a range like this, I cant figure it out, anyone come across this before? if($town == "") { $town = '%'; } if($proptype == "") { $proptype = '%'; } $result = mysql_query("SELECT hvtid, paddress, town, state, mls, remarks, proptype, tbrooms, listprice, lotdim, annualt FROM properties WHERE hvtid = '$hvtid' OR (proptype LIKE '%$proptype%' AND town LIKE '%$town%' AND state = '$state' AND listprice >= '$mprice' AND listprice <= '$maxprice' AND areaint >= '$areaint' OR proptype = '$proptype' AND zip = '$zip' AND listprice >= '$mprice' AND listprice <= '$maxprice') AND status = 'Active'"); $countrows = mysql_num_rows($result); if($countrows == NULL) { echo ("Your search found no results."); Link to comment https://forums.phpfreaks.com/topic/42889-solved-problem-with-searching-a-table/ Share on other sites More sharing options...
effigy Posted March 15, 2007 Share Posted March 15, 2007 - What data type is listprice in your table? - What does your SQL statement look like after the variables have been interpolated? - You may want to use BETWEEN. Link to comment https://forums.phpfreaks.com/topic/42889-solved-problem-with-searching-a-table/#findComment-208310 Share on other sites More sharing options...
darknessmdk Posted March 15, 2007 Author Share Posted March 15, 2007 listprice is text in my table and I tried between and got the same results Link to comment https://forums.phpfreaks.com/topic/42889-solved-problem-with-searching-a-table/#findComment-208318 Share on other sites More sharing options...
effigy Posted March 15, 2007 Share Posted March 15, 2007 Why are you storing numeric data in a text column? MySQL has to make a conversion, which gives you the unexpected results. I'm not sure if this is the best way--other than changing the database--but it should work if a comma is the only non-digit character in the field. CAST(REPLACE(listprice, ',', '') AS UNSIGNED) BETWEEN 1 AND 100000 Link to comment https://forums.phpfreaks.com/topic/42889-solved-problem-with-searching-a-table/#findComment-208356 Share on other sites More sharing options...
darknessmdk Posted March 16, 2007 Author Share Posted March 16, 2007 I made the field text because there is the possibility of N/A being inserted into the field. Link to comment https://forums.phpfreaks.com/topic/42889-solved-problem-with-searching-a-table/#findComment-208733 Share on other sites More sharing options...
darknessmdk Posted March 16, 2007 Author Share Posted March 16, 2007 Can you use BETWEEN with a field that contains text and intigers? Link to comment https://forums.phpfreaks.com/topic/42889-solved-problem-with-searching-a-table/#findComment-208902 Share on other sites More sharing options...
effigy Posted March 16, 2007 Share Posted March 16, 2007 See BETWEEN. Link to comment https://forums.phpfreaks.com/topic/42889-solved-problem-with-searching-a-table/#findComment-208907 Share on other sites More sharing options...
darknessmdk Posted March 22, 2007 Author Share Posted March 22, 2007 Thanks I got it working now! Link to comment https://forums.phpfreaks.com/topic/42889-solved-problem-with-searching-a-table/#findComment-212546 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.