Jump to content

Sorting


spearchilduser

Recommended Posts

As they are searching by Price they will be able to in the example untill it work order by NUMBER OF BEDROOMS OR The house number and ive come up with:

 

$order = $_POST['order'];

$query = "SELECT * FROM properties WHERE Number_of_Bedrooms ='".$_POST['Number_of_Bedrooms']."' ORDER BY '".$_POST['order']."' DESC";

$result = mysql_query($query);

 

 

im guessing its incorrect somehow as it makes no effect on the statement

Im guessing it could be as ive not said that  '".$_POST['order']."'  needs to look at the Field in which is sent across im not to sure how to do this bit :(

Link to comment
https://forums.phpfreaks.com/topic/254953-sorting/#findComment-1307246
Share on other sites

you will probably want something like a dropdown to send the order by through to the POST variable:

<!--include this within your form at a relevent part -->
<select name="order">
  <option value="price" selected="selected">Price</option>
  <option value="Number_of_Bedrooms">Number of bedrooms</option>
<!-- include as many other options as you need making sure the value for each is the same as your column names in your database table -->
</select>

Link to comment
https://forums.phpfreaks.com/topic/254953-sorting/#findComment-1307256
Share on other sites

Ok

but if the user is selecting the order value from a dropbox im posting the information over like this

 

$order = $_POST['order'];

AS IVE named the drop box order

 

Then in the query i have said to

ORDER BY '".$order."' ASC ";

 

How ever i havent said anywhere what option 1 ( lets say this is house number ) relates to

 

would i do this in another case by saying if case 1 is selected order by Price if case2 is selected order by house number etc ?

Link to comment
https://forums.phpfreaks.com/topic/254953-sorting/#findComment-1307257
Share on other sites

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.