note 50644 added to function.ldap-sort

From: Date: Sat, 05 Mar 2005 17:30:11 +0000
Subject: note 50644 added to function.ldap-sort
Groups: php.notes 
Request: Send a blank email to php-notes+get-85975@lists.php.net to get a copy of this message
It is interesting people are using all these methods to sort multi-attribute results from LDAP searches. Well, here is a simpler one. Just use ldap_sort once for each sort attribute in the reverse order of importance. --hikmet <?php $ldapFilterAttributes = array ('givenname', 'sn', 'mail'); $ldapSortAttribues = array('sn', 'givenname'); // ie. sort by givenname, then by sn $ldapFilter = "(&(sn='')(givenname=''))"; $ldapBaseDN = 'ou=users, dc=example, dc=com'; $search = @ldap_search($ldapConnect, $ldapBaseDN, $ldapFilter, $ldapFilterAttributes) ; if (!($search)) { die("Unable to search LDAP server"); } // lets sort the results by firstname if firstname is in the results foreach ($ldapSortAttributes as $eachSortAttribute) { if (in_array($eachSortAttribute, $ldapFilterAttributes)) { // making sure we don't accidentally try to sort against an inexisting field ldap_sort($this->connect, $search, $eachSortAttribute); } } // and here is the result $results = ldap_get_entries($this->connect, $search); ?> ---- Manual Page -- http://www.php.net/manual/en/function.ldap-sort.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50644 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50644&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50644&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50644&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50644&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50644&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50644&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85975) next »