PHP Filtering Results

I want to create a feature , where when a user clicks ‘Detached Houses’ then only detached houses will be displayed. if a user clicks ‘Semi-detached’ then only semi detached houses will be shown from a MYSQL database that is already set up.
Any help is really appreciated, thank you.

[php]



Houses


Detached Houses

<?php // Make a MySQL Connection mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); // Get a specific result from the "example" table $result = mysql_query("SELECT * FROM example WHERE name='Sandy Smith'") or die(mysql_error()); $query = "SELECT * FROM example"; if(isset($_GET['type'])) { $query .= " WHERE type = '" . mysql_real_escape_string($_GET['type']) . "'"; } // get the first (and hopefully only) entry from the result $row = mysql_fetch_array( $result ); // Print out the contents of each row into a table echo $row['name']." - ".$row['age']; ?>
					<br />
					<span class="dh"><b><u>Semi-detached houses</u></b></span>						
					<br />
					<span class="dh"><b><u>Terraced houses</u></b></span>
					<br />
					<br />
					<b><u>Flats / Apartments</u></b>

</p></div></td>

[/php]

Really need some help on getting this sorted, I would really appreciate it, thank you.

Well, normally this would be done inside your query. You would have various options in the apartment table that would indicate what they are. Such as number_of_bedrooms, number_of_bathrooms, views, detached_houses, etc…

Then, inside the query that pulls the apartments, you would add options such as "WHERE number_of_bedrooms=‘3’ and detached_houses=‘yes’ " … Something like that.

On your form that the user starts at, there would be input fields that are either radio buttons or check boxes and your PHP code would read these. Using $_POST[‘detached_houses_checkbox’]… Then, if checked it would add this query option to the query before it is executed…

Hope that helps… Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service