Interista Posted October 26, 2012 Share Posted October 26, 2012 Hello, How I can sort MySQL result . I have to two selects box , Sort by alphabetical and sort by the categories , the two selects box in the same page . How I can filter the result according of the sort type . Like sort the result by specific category and in the same time sort it from Z to A . / DESC Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 26, 2012 Share Posted October 26, 2012 (edited) $sql = "SELECT * FROM `whatever` ORDER BY `category` DESC"; Edited October 26, 2012 by ExtremeGaming Quote Link to comment Share on other sites More sharing options...
Interista Posted October 26, 2012 Author Share Posted October 26, 2012 $sql = "SELECT * FROM `whatever` ORDER BY `category` DESC"; OK I know that , But How I can sort the result of this query like sort it according the category . the only way use queries ? Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 26, 2012 Share Posted October 26, 2012 (edited) ORDER BY `category` DESC Will order it in descending order in the alphabet Sorry but that's all I can figure out by the way you worded it Edited October 26, 2012 by ExtremeGaming Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 26, 2012 Share Posted October 26, 2012 ORDER BY category DESC, name DESC Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 26, 2012 Share Posted October 26, 2012 ORDER BY category DESC, name DESC Oops, I get what you meant now...sorry Quote Link to comment Share on other sites More sharing options...
Interista Posted October 27, 2012 Author Share Posted October 27, 2012 So that mean there is no way to do it using like functions in jQuery or anything else .. ! so I should make a functions with queries for all sort facilities available . Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 27, 2012 Share Posted October 27, 2012 I just told you how... What are you asking? Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 27, 2012 Share Posted October 27, 2012 you can sort data in any programming language on any computer. you really need to be more specific. why is sorting it in the query not sufficient for your needs? Quote Link to comment Share on other sites More sharing options...
Interista Posted October 27, 2012 Author Share Posted October 27, 2012 Sorry for not being clear , But the problems that I face is hard to do it in the query for me . because I want to sort result after filter it according to category type . so as example if I have a 5 rows , and filter it using category type it will be like 3 rows as example . How I can sort only the 3 rows not the whole result of the first query . I hope it's a clear now :$ Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 27, 2012 Share Posted October 27, 2012 Still not very clear to me but you can limit results using LIMIT 3 in your query Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 27, 2012 Share Posted October 27, 2012 WHERE category = 'category' ORDER BY name DESC Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 27, 2012 Share Posted October 27, 2012 WHERE category = 'category' ORDER BY name DESC Seriously, sorting and filtering is the reason for SQL's existence. That's what it's for. Quote Link to comment 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.