1

I'm trying to make a search for a property website i'm working on for a friend. In the Database the property types are named by id numbers, ie: house = 30, flat = 8, terraced =1, and so forth..

How can i retrieve ALL properties from the database when some are detached houses with value of 2 and houses are value of 30 etc :) It has got me stuck..lol Here's what i have so far which isn't working...

$bedrooms = $_GET['bedrooms'];
$pricefrom = $_GET['pricefrom'];
$priceto = $_GET['priceto'];
$proptype = $_GET['proptype'];

if($proptype == 'house'){
$search_propsubid = array('1,2,3,4,5,6,21,22,23,24,26,27,30');
}elseif($proptype == 'flat'){
$search_propsubid = array('7,8,9,10,11,28,29,44');
}elseif($proptype == 'bungalow'){
$search_propsubid = array('');
}


$sql = mysql_query("SELECT * FROM `properties` WHERE `PROP_SUB_ID`='$search_propsubid' AND `BEDROOMS`='$bedrooms' AND `TRANS_TYPE_ID`='1' HAVING `PRICE` BETWEEN '$pricefrom' AND '$priceto' ORDER BY `UPDATE_DATE` DESC");

Thank you for your time i hope someone can point me in the right direction.. Regards Steve

2 Answers 2

1

You can try to implode array:

$search_propsubid = array('1,2,3,4,5,6,21,22,23,24,26,27,30');
$comma_separated = implode(",", $search_propsubid);
$sql = mysql_query("SELECT * FROM `properties` WHERE `PROP_SUB_ID` in ($comma_separated) ...

Comme back with news if this don't works for you.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so very much :D Works a treat, so grateful !!
@danihp, +'d, I don't want to be on a firefight with you ;)
1

You can use the MySql IN() comparison operator to select all that match the list of values:

$sql = mysql_query("
  SELECT * 
  FROM `properties` 
  WHERE `PROP_SUB_ID` IN (" .implode(",", $search_propsubid). ")
  AND `BEDROOMS`='$bedrooms' 
  AND `TRANS_TYPE_ID`='1' 
  HAVING `PRICE` BETWEEN '$pricefrom' AND '$priceto' 
  ORDER BY `UPDATE_DATE` DESC
");

Assuming $proptype == 'flat', the output will be:

SELECT *
FROM `properties` 
WHERE `PROP_SUB_ID` IN (7,8,9,10,11,28,29,44) 
...

2 Comments

Hello thank you for your reply, i'm very grateful you took the time to offer your help :) Your answer is very similar in nature to the first one which worked perfectly for me. Thank you for your time :)
Steve, Yap I saw @danihp answer when I've finished publishing my answer... getting the right links and run a test does take some time :) Glad your problem is solved!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.