RE: [PHP] sorting data from a field
you can extract and sort on the last name: mysql> select substring(myname,locate(" ",myname)+1) as lname from mytable order by lname; this assumes names are stored as "john doe", that is with a space separator -Original Message- From: Chuck Barnett [mailto:[EMAIL PROTECTED]] Sent: Sunday, February 03, 2002 2:50 PM To: PHP General List Subject: [PHP] sorting data from a field Hello again :) I have a db field that holds the first and last name of a person. Is there a way to sort by the last name in that field? The whole reason for this is to populate a select box sorted by last name. I don't want to go back and create a separate field if I don't have to. Any help is appreciated. Thanks, Chuck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sorting data from a field
To do that is it necesary to loop the $result variable and assign each array($name => $value) ? > Alternately, you can load all of the unsorted results into an associative > array, and use PHP's native sorting functions (such as ksort() ) to sort the > results. > > > Darren Gamble > Planner, Regional Services > Shaw Cablesystems GP > 630 - 3rd Avenue SW > Calgary, Alberta, Canada > T2P 4L4 > (403) 781-4948 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] sorting data from a field
Good day, Sorry, I didn't read your request as clearly as I should have. =) If you have a single field, the best way would be to load all of the results, and then have PHP split() the results by whitespace. Then store the results by associative array and use ksort() to sort them. The best way would be to have a first name and last name field. This addresses situations where people have their family name first and their given name second. Darren Gamble Planner, Regional Services Shaw Cablesystems GP 630 - 3rd Avenue SW Calgary, Alberta, Canada T2P 4L4 (403) 781-4948 -Original Message- From: Darren Gamble [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 26, 2002 2:13 PM To: 'Chuck Barnett'; PHP General List Subject: RE: [PHP] sorting data from a field Good day. You can do this using the "ORDER" clause in SQL. Please consult your particular database's documentation for more information. Alternately, you can load all of the unsorted results into an associative array, and use PHP's native sorting functions (such as ksort() ) to sort the results. Darren Gamble Planner, Regional Services Shaw Cablesystems GP 630 - 3rd Avenue SW Calgary, Alberta, Canada T2P 4L4 (403) 781-4948 -Original Message- From: Chuck Barnett [mailto:[EMAIL PROTECTED]] Sent: Sunday, February 03, 2002 1:50 PM To: PHP General List Subject: [PHP] sorting data from a field Hello again :) I have a db field that holds the first and last name of a person. Is there a way to sort by the last name in that field? The whole reason for this is to populate a select box sorted by last name. I don't want to go back and create a separate field if I don't have to. Any help is appreciated. Thanks, Chuck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] sorting data from a field
Good day. You can do this using the "ORDER" clause in SQL. Please consult your particular database's documentation for more information. Alternately, you can load all of the unsorted results into an associative array, and use PHP's native sorting functions (such as ksort() ) to sort the results. Darren Gamble Planner, Regional Services Shaw Cablesystems GP 630 - 3rd Avenue SW Calgary, Alberta, Canada T2P 4L4 (403) 781-4948 -Original Message- From: Chuck Barnett [mailto:[EMAIL PROTECTED]] Sent: Sunday, February 03, 2002 1:50 PM To: PHP General List Subject: [PHP] sorting data from a field Hello again :) I have a db field that holds the first and last name of a person. Is there a way to sort by the last name in that field? The whole reason for this is to populate a select box sorted by last name. I don't want to go back and create a separate field if I don't have to. Any help is appreciated. Thanks, Chuck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sorting data from a field
On Sun, 3 Feb 2002, Chuck Barnett wrote: > I have a db field that holds the first and last name of a person. Is > there a way to sort by the last name in that field? > > The whole reason for this is to populate a select box sorted by last name. > > I don't want to go back and create a separate field if I don't have to. You can do something cheesy like this: select name from table order by substring(name, locate(' ', name)) but really I'd advise splitting it into separate fields because your queries will run faster and you'll have more flexibility in the long term. miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php