angel1987 Posted June 24, 2010 Share Posted June 24, 2010 I am tired of searching online because everywhere it says use ORDER BY ..... ASC | DESC. But that does not work for ordering data in alphabetical order. I don't understand how come that is working for so many people? My query is: "SELECT * FROM categories WHERE parentid = '$getid'"; I am listing categories on left side bar and there are more than 70 categories. I want them to appear in alphabetical order starting from A - Z. I know there is some different syntax in sql query for ordering data alphabetically because i saw it once and it worked but i just forgot where i read it and now i am lost. Quote Link to comment https://forums.phpfreaks.com/topic/205704-how-to-sort-data-from-a-table-in-alphabetical-order/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 24, 2010 Share Posted June 24, 2010 Since you did not show the query you tried using ORDER BY and the output you did get, it is a little hard for anyone one here to tell you why it did not work. Quote Link to comment https://forums.phpfreaks.com/topic/205704-how-to-sort-data-from-a-table-in-alphabetical-order/#findComment-1076357 Share on other sites More sharing options...
angel1987 Posted June 24, 2010 Author Share Posted June 24, 2010 Ok, here is the query with ORDER BY "SELECT * FROM categories WHERE parentid = '$getid' ORDER BY category DESC"; category is the column with names of the category. Quote Link to comment https://forums.phpfreaks.com/topic/205704-how-to-sort-data-from-a-table-in-alphabetical-order/#findComment-1076358 Share on other sites More sharing options...
PFMaBiSmAd Posted June 24, 2010 Share Posted June 24, 2010 And that gave you output in DESCending alphabetical order didn't it? Quote Link to comment https://forums.phpfreaks.com/topic/205704-how-to-sort-data-from-a-table-in-alphabetical-order/#findComment-1076360 Share on other sites More sharing options...
angel1987 Posted June 24, 2010 Author Share Posted June 24, 2010 Ok it gave me a DESC order from Z - A and so i made it ASC and it gave me an order from A-Z but it is also showing categories starting from I, P and S before A. Quote Link to comment https://forums.phpfreaks.com/topic/205704-how-to-sort-data-from-a-table-in-alphabetical-order/#findComment-1076364 Share on other sites More sharing options...
PFMaBiSmAd Posted June 24, 2010 Share Posted June 24, 2010 Your data probably contains white-space/non-printing characters (spaces, carriage-returns, nulls, line-feeds, ...) that is causing it be sorted out of order. Where did your data originate and how did it get inserted into your table? There are literally millions of php based web sites that use ORDER BY in queries that work. Had you stated or shown what results you are getting in your first post in this thread (where it belonged), you could have gotten an answer quicker, rather than playing around with what problem you actually are having. Quote Link to comment https://forums.phpfreaks.com/topic/205704-how-to-sort-data-from-a-table-in-alphabetical-order/#findComment-1076366 Share on other sites More sharing options...
angel1987 Posted June 24, 2010 Author Share Posted June 24, 2010 Ok there was no spaces or special characters but i just deleted those records and added them again from the admin section and it worked. Thanks very much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/205704-how-to-sort-data-from-a-table-in-alphabetical-order/#findComment-1076368 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.