Jump to content

[SOLVED] Problem with Searching a table


darknessmdk

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.