Darkmatter5 Posted October 21, 2008 Share Posted October 21, 2008 I have a dropdown list that's dynamically constructed from a MySQL query. There are 3 fields I am currently sorting by: SELECT client_id, first_name, last_name, company_name FROM $dbname.clients ORDER BY last_name ASC, first_name ASC, company_name ASC I'm wanting to now sort last_name and company_name together and also order first_name when last_name is being used to sort. This sounds confusing, here's an example of a desired list. ABC, Inc. Bowling, John Branch, Ltd. Smith, John Toff, Jerry Toff, Mary YYZ Rush, Inc. As you can see the first, third and seventh entries are company_names. The second, fourth, fifth and sixth entries are last_name with firstname. Notice the fifth and sixth entries are the same last_name, but different first_names, but are grouped together by last_name and then subordered by first_name. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/129399-solved-sort-by-multiple-fields-mysql/ Share on other sites More sharing options...
fenway Posted October 22, 2008 Share Posted October 22, 2008 I'm wanting to now sort last_name and company_name together and also order first_name when last_name is being used to sort. I don't understand. Quote Link to comment https://forums.phpfreaks.com/topic/129399-solved-sort-by-multiple-fields-mysql/#findComment-672030 Share on other sites More sharing options...
Darkmatter5 Posted October 22, 2008 Author Share Posted October 22, 2008 Never mind, I created a new field in my clients table named full_name, wrote a script to construct the full_name field from last_name, first_name and company_name and then used full_name to generate my list. Thanks for the reply though. Quote Link to comment https://forums.phpfreaks.com/topic/129399-solved-sort-by-multiple-fields-mysql/#findComment-672054 Share on other sites More sharing options...
fenway Posted October 22, 2008 Share Posted October 22, 2008 Sounds like a concat might have worked...whatever. Quote Link to comment https://forums.phpfreaks.com/topic/129399-solved-sort-by-multiple-fields-mysql/#findComment-672066 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.