On Wed, Nov 28, 2001 at 03:08:52PM +0930, [EMAIL PROTECTED] wrote:
Hi All-
Can anyone tell me if PHP's LDAP functions support server side sorting of
search results as defined in this RFC:
http://www.ietf.org/rfc/rfc2891.txt
Not currently, maybe it will... Depends on how many wants it.
Sorting results from LDAP searches in PHP is a pain because of the
structure
of the result array.
Yes, but I think that's a poor excuse for doing it on the server side.
I think this should be done by the client in most cases. One might
also need to take the clients locale into account when sorting the
data.
Alternatively if anyone has a nice function for sorting the array returned
by
ldap_get_entries() by any desired attribute, that would be a great help
also.
It's not that hard. What I do, is that I create a new simple array
with just the attribute values I want to sort on and preserve the
indices of the result array. Next I sort that array (again
preserving indices). The indices of the sorted array now give me
the order I should use when displaying the entries from the result
array. Not that hard, it looks something like this:
$n=ldap_count_entries($ds,$sr);
$info = ldap_get_entries($ds, $sr);
ldap_free_result($sr);
for ($i=0; $i$n; $i++) {
$cn[$i]=$info[$i][cn][0]);
}
asort($cn);
reset($cn);
for ($j=0; list($i,) = each($cn);) {
$sorted[$j] = $info[$i];
}
Anyway, the next PHP release (in CVS or snapshots now) will have a
function ldap_sort() for client side sorting. After you've done
the search, simply do ldap_sort($ds, $sr, cn);
and you have sorted the results on cn, and you access the result
as usual afterwards.
Stig
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]