Sorting, sort of
| From: | Jason Soza | Date: | Mon, 06 May 2002 19:25:03 +0000 |
| Subject: | Sorting, sort of | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-96311@lists.php.net to get a copy of this message | ||
I have a 'name' field in a MySQL table that contains people's first and
last names, i.e. "John Smith" - but some people may choose not to
include their last name, so they're just "John" in the table, or they
may choose to include themselves and someone else, but not the last
name, "John and Jane".
I'm thinking the easiest way to sort by last name, which is what I want
to do, is to just go into MySQL and make 'first_name' and 'last_name'
fields, but if there's a way to do this with PHP that'd be great, so
then I wouldn't have to mess with the table and data.
Anyhow, I've looked up sort() and asort() in the PHP manual, but I'm
not sure how I'd go about this. I assume I'd use some kind of function
to read the 'name' field to the first space, take what it finds after
the space and put it into an array, then have some if/else statement to
deal with the lack of a space or the presence of multiple spaces, then
use sort() on that array.
Just looking for some guidance, maybe a specific function or bit of
code. Anything that'd help. Or if this would be more easily addressed
by reconfiguring my MySQL table, just let me know.
Thanks,
Jason Soza