On Monday 13 May 2002 00:23, Nick Wilson wrote:
> Hi all,
> I hope someone might help me with a little puzzle...
> I have bunch of db results and one of the fields is 'name',
> I want to see if there are 2 parts to it like FirstName LastName and if
> so order by the last name.
> I can see explode() being the php function I need here but am a little
> lost as to what will happen if there is only one word in the name var.
> If someone can suggest what I might do that would be great!
> many thanks...

Not knowing exactly what it is you want I'm assuming the following: if there 
is a lastname use that in the sort, otherwise use the firstname. Thus your 
sorted list will look something like:

  Bryan Adams (Adams, Bryan)
  John Butcher (Butcher, John)

If that is what you want then:
while (names) {
  explode the name
  if there is more than one element swap it, then join
  add this processed name onto a new array

use one of the array sort functions to sort the new array.

Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

Wagner's music is better than it sounds.
                -- Mark Twain

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to