Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/129399-solved-sort-by-multiple-fields-mysql/
Share on other sites

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.

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.