tags:

views:

86

answers:

3
A: 

You want to use the WHERE clause. You can have multiple conditions joined by boolean operators such as AND or OR. For example:

SELECT ... WHERE
    type = 123
    AND rent BETWEEN 100 AND 200
    AND city = 567
    AND area LIKE '%Name of an area%'
Lukáš Lalinský
A: 

Something like that :

SELECT *
FROM ads
WHERE type = 'Living House'
AND rent > 50 AND rent < 300
AND city = 'London'
AND area LIKE '%westminster%'

You can take a look at W3School's SQL Tutorial for more informations about SQL basics.

Damien MATHIEU
+1  A: 

Selecting records from MySQL table is basic task. I recommend you to read W3schools tutorial on SQL.

What you want here is done with one simple SELECT query:

//Connecting to MySQL and selecting DB
mysql_connect('server', 'user', 'password');
mysql_select_db('database');

//Actual SELECT query
$qh = mysql_query("SELECT * FROM table_name WHERE city='".$_POST['city']."' AND rent='".$_POST['rent']."' AND area='".$_POST['area']."'");

//Getting query results by rows
while($row = mysql_fetch_assoc($qh))
{
   //Do something with $row here
}

EDIT: I used $_POST variable just for simplicity. Note that you should always check/validate it's content before using it in a query this way. (To prevent SQL injection)

Petr Peller
Calling `mysql_real_escape_string` in the example is not that hard and it might help people who just blindly copy the code. (Yes, copying code without understanding it is a terrible idea, but why not show good examples.)
Lukáš Lalinský