[lug] alpha sort for ldap query in php

Andrew Diederich andrew at NETdelivery.com
Tue Oct 31 15:49:50 MST 2000


I'm trying my hand at a (very) little php scripting.  The one thing I wanted
to do was grab name/email/phone info out of an MS exchange ldap directory.
I go the basics down (the query happens, tables appear with the right data,
etc.) but it isn't sorted alphabetically.  It seems to be sorted in the
order that the users were added to exchange.  

Does anyone know a good way to alphabatize this?  Right now my table entries
look like the below.  I stole much of this from the php website.  I took out
the actual <table> bits to make this email a little shorter.

$ds=ldap_connect("host.name"); // must be a valid LDAP server!
if ($ds) {
        $r=ldap_bind($ds);      // this is an "anonymous" bind, typically
                                // read-only access
$dn="";
$sr=ldap_search($ds, $dn, "objectclass=organizationalperson");
$info = ldap_get_entries($ds, $sr);
$info = ldap_get_entries($ds, $sr);
for ($i=0; $i<$info["count"]; $i++) {
        echo "<tr>\n<td>".$info[$i]["cn"][0]."</td>\n";
        echo "<td>".$info[$i]["telephonenumber"][0]."</td>\n";
        echo "<td>".$info[$i]["mail"][0]."</td>\n";
        echo "<td>".$info[$i]["title"][0]."</td>\n";
        echo "</tr>\n\n";
}

Any ideas?
--
    Andrew Diederich




More information about the LUG mailing list