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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.