Re: arg, sort the results of an LDAP search

From: Date: Thu, 27 Jul 2000 12:30:48 +0000
Subject: Re: arg, sort the results of an LDAP search
Groups: php.general 
Request: Send a blank email to php-general+get-8541@lists.php.net to get a copy of this message
You can try the method I use, which is to use ksort(), having pulled the result of the LDAP search into an associative array where the key is what you want sorted. Something like this (cut from real working code!) $num = $info["count"]; for ($i=0; $i<$num; $i++){ $names[$info[$i]["givenname"][0].$info[$i]["sn"][0]] = array($info[$i]["givenname"][0], $info[$i]["sn"][0], $info[$i]["mail"][0], $info[$i]["ou"][0]); } ksort($names); The items you want in the array will of course vary according to which attributes you have asked to be returned. HTH - Nick Nick Talbott IT Policy and Strategy Manager, Powys County Council, UK email nickt@powys.gov.uk FAX +44 (0) 1597 824781 web http://www.powys.gov.uk and http://www.powysweb.co.uk -----Original Message----- From: Angus Mackay <amackay@gusnet.cx> To: php-general@lists.php.net <php-general@lists.php.net> Date: 26 July 2000 20:58 Subject: [PHP] arg, sort the results of an LDAP search >I have banged my head into a wall long enough with this. I need to sort the >results of an ldap_search via my own method (givenname . sn instead of the >default uid). > >anyway everything I have tried does not work. > >here is the code that I think should work: > $sr=ldap_search($ds, $dn, $filter, $justthese); > if(!$sr) { return; } > $info = ldap_get_entries($ds, $sr); > > function cmp($a, $b) > { > if(!is_array($a) || !is_array($b)) > { > return(-1); > } > $A = $a['givenname'][0] . $a['sn'][0]; > $B = $b['givenname'][0] . $b['sn'][0]; > echo "A: ", $A, "\n"; > echo "B: ", $B, "\n"; > return(strcmp($A, $B)); > } > uasort($info, cmp); > >this doesn't change $info at all though. it does print out all the right A:, B: comparisons though. > >I am sure that someone has to have wanted to sort the results of an ldap search before. please help! > >cheers, Angus. > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net >For additional commands, e-mail: php-general-help@lists.php.net >To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#8541) next »