MySQL/PHP queries

Does anyone know of any books that would explain how to do a query search from something like an estate agent? (I think in America you call it Real Estate though)

As in search for a property for example between £300,000 - £500,000 only detached houses with more than 5 bedrooms.

I don’t want any open source CMS’s as it’s something I want to learn rather than just implement.

The problem is, I’m not sure what the term is of what I’m trying to do so can’t search for it. It doesn’t have to just be books any online examples would be really helpful too.

Here is an example of a site I’ve built with what I’m talking about.

I did get a coder to write a page that will do it but now I want to learn how it’s done

Thanks for any help.

It’s a structured data search, where you take the form values and build the SQL query dynamically.


$query = "SELECT * FROM properties WHERE 1=1";

//Minimum price
if($_POST['min_price'] != 0) {
  $query .= " AND price >= " . (int)$_POST['min_price'];

//Max price
if($_POST['max_price'] != 0) {
  $query .= " AND price <= " . (int)$_POST['max_price'];

if($POST['bedrooms'] != 0) {
  $query .= " AND bedrooms >= " . (int)$_POST['bedrooms'];

//Dwelling Types
$allowed_types = array('detached', 'aerodynamic', 'underwater', 'dilapidated');
if(in_array($_POST['type'], $allowed_types)) {
  $query .= " AND `type` = '" . $_POST['type'] . "'";

echo $query;

So the query gets more restrictive the more attributes the user specifies. If everything was blank the query would just get the whole table.