sorting names
Posted: Tue Dec 11, 2007 5:52 pm
I have a page where the user can sort client names from the database.
My problem is that these names are stored in different columns. There are residential customers and commercial customers.
All data is in the same table as follows:
Residential customers
cust_firstname and cust_lastname
Commercial customers
cust_companyname
I have the sort page done and working if it only needs to sort either residential names or commercial names. The problem is when they all need to be sorted in the same list.
For example I have these four clients
John Smith (residential)
Bruce Willis (residential)
ABC Distributing (commercial)
Microsoft (commercial)
Then when sorted it should be
BY FIRST NAME
ABC Distributing, Bruce Willis, John Smith, Microsoft
BY LAST NAME
ABC Distributing, Microsoft, John Smith, Bruce Willis
So I think there's a sort function that re-sorts the value of an array. How is that done on more than one at the same time?
After the data's been pulled from the database it is stored in four arrays as follows:
How can I re-sort them alphabetically where it's based on two columns? Either last name and company name or first name and company name.
My idea would be to move the company name to the first name or last name column based on the sort requirement. Like so:
This is based on ORDER BY FIRST NAME
Once it's done I need to sort the value of clientFirstName array alphabetically and all the other arrays in the same fashion.
Can someone help me figure out how to do that?
Or is it possible to query the database directly to get the results in my arrays already in that order?
Thanks
My problem is that these names are stored in different columns. There are residential customers and commercial customers.
All data is in the same table as follows:
Residential customers
cust_firstname and cust_lastname
Commercial customers
cust_companyname
I have the sort page done and working if it only needs to sort either residential names or commercial names. The problem is when they all need to be sorted in the same list.
For example I have these four clients
John Smith (residential)
Bruce Willis (residential)
ABC Distributing (commercial)
Microsoft (commercial)
Then when sorted it should be
BY FIRST NAME
ABC Distributing, Bruce Willis, John Smith, Microsoft
BY LAST NAME
ABC Distributing, Microsoft, John Smith, Bruce Willis
So I think there's a sort function that re-sorts the value of an array. How is that done on more than one at the same time?
After the data's been pulled from the database it is stored in four arrays as follows:
Code: Select all
clientID[] clientFirstName[] clientLastName[] clientCompanyName[]
12 John Smith NULL
23 Bruce Willis NULL
74 NULL NULL Microsoft
89 NULL NULL ABC DistributingMy idea would be to move the company name to the first name or last name column based on the sort requirement. Like so:
This is based on ORDER BY FIRST NAME
Code: Select all
clientID[] clientFirstName[] clientLastName[] clientCompanyName[]
12 John Smith NULL
23 Bruce Willis NULL
74 Microsoft NULL NULL
89 ABC Distributing NULL NULLCan someone help me figure out how to do that?
Or is it possible to query the database directly to get the results in my arrays already in that order?
Thanks