Re: sorting LDAP queries... (yes, again)
| From: | Nick Talbott | Date: | Thu, 28 Sep 2000 07:42:11 +0000 |
| Subject: | Re: sorting LDAP queries... (yes, again) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-17873@lists.php.net to get a copy of this message | ||
>OK, I'm running a query against our LDAP server and outputting the
>results to PDF via PHP. All works great except, of course, the results
>are not alphabetical. SO I tried the much overused and malfinctioning
[snip]
Try this approach:
Run your LDAP query
Copy returned data to a key->value associative array,
making the key the field(s) you want to sort on.
use ksort()
eg
$info = ldap_get_entries(... );
$num = count($info);
for ($i=0; $i<$num; $i++){
$names[$info[$i]["sn"][0].$info[$i]["givenname"][0]]
= array($info[$i]["givenname"][0],
$info[$i]["sn"][0],
$info[$i]["mail"][0]);
}
ksort($names);
This gives you the $names array sorted on sn+givenname assuming your LDAP
query was for sn, givenname and mail
Regards
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