You _definetly_ want to do this in your database, not with PHP and arrays.
Databases are made to do this kind of sorting for you.

I would modify your table first, adding in another column for first_name,
then modify your form so that all data going in from now on is correct. The
hard part will be getting the data you have now into the correct format. How
big of a table are we talking?

---John Holmes...

----- Original Message -----
From: "Jason Soza" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 06, 2002 3:25 PM
Subject: [PHP] Sorting, sort of


> 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
>
>
> --
> 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

Reply via email to