spearchilduser Posted January 13, 2012 Share Posted January 13, 2012 Just a further question from a earlier post that was complete if i do a search and i want to order them from a drop box the if statement would it just look like "select * from Table order by '".$_POST['order']."'" Or would this not work ? Thanx Quote Link to comment https://forums.phpfreaks.com/topic/254953-sorting/ Share on other sites More sharing options...
Muddy_Funster Posted January 13, 2012 Share Posted January 13, 2012 that should be fine yeah. Quote Link to comment https://forums.phpfreaks.com/topic/254953-sorting/#findComment-1307240 Share on other sites More sharing options...
spearchilduser Posted January 13, 2012 Author Share Posted January 13, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/254953-sorting/#findComment-1307246 Share on other sites More sharing options...
spearchilduser Posted January 13, 2012 Author Share Posted January 13, 2012 sorry the below statment wa made on when they search usign number of bedrooms but the syntax will stay the same Quote Link to comment https://forums.phpfreaks.com/topic/254953-sorting/#findComment-1307248 Share on other sites More sharing options...
litebearer Posted January 13, 2012 Share Posted January 13, 2012 correct, you need to specify which field you want it ordered by ie ORDER BY price (this is the field name) Quote Link to comment https://forums.phpfreaks.com/topic/254953-sorting/#findComment-1307252 Share on other sites More sharing options...
Muddy_Funster Posted January 13, 2012 Share Posted January 13, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/254953-sorting/#findComment-1307256 Share on other sites More sharing options...
spearchilduser Posted January 13, 2012 Author Share Posted January 13, 2012 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/254953-sorting/#findComment-1307257 Share on other sites More sharing options...
spearchilduser Posted January 13, 2012 Author Share Posted January 13, 2012 and sorry i was typing as you replyed muddy i have a drop box set up to send the options across alrready set out exaclty the same Quote Link to comment https://forums.phpfreaks.com/topic/254953-sorting/#findComment-1307259 Share on other sites More sharing options...
Muddy_Funster Posted January 13, 2012 Share Posted January 13, 2012 just use the value="" atribute of the option element to relate to your field name just now, re-read my sample code for a better explination Quote Link to comment https://forums.phpfreaks.com/topic/254953-sorting/#findComment-1307260 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.