sorting LDAP queries... (yes, again)
| From: | Steve Neuharth | Date: | Thu, 28 Sep 2000 04:38:42 +0000 |
| Subject: | sorting LDAP queries... (yes, again) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-17856@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
example of....
function Compare($a,$b){
$sortfield = "userid";
if($a[$sortfield]==$b[$sortfield]) {
return 0;
}
if($a[$sortfield]>$b[$sortfield]) {
return 1;
} else {
return -1;
}
}
usort($entries,Compare);
This only cleared out the array I passed it.... So I modified it like
this....
function Compare($a,$b) {
$sortfield = "surname";
$c=$a[$sortfield][0];
$d=$b[$sortfield][0];
if($c==$d) {
echo $c.$d."=<BR>" ;
return 0;
}
if($c>$d) {
echo $c.$d."><BR>" ;
return 1;
} else {
return -1;
}
}
usort($entries,Compare);
uksort($entries,Compare);
uasort($entries,Compare);
of the three uksort() seems to be actually doing the sort, but still
returns the array unsorted.
Somebody HAS to have done this before (successfully). Has anybody out
there done it? It'd be REALLY nice if the ldap_sort() function were
thrown into php sometime soon, but until then.... anybody got any
working code or good advice?