Hi all,
I'm a real rookie at PHP. I've done an LDAP query on Active Directory but cannot figure out how to sort the results. Here's what I have so far:
// ====== P R O C E S S ======
$connect = ldap_connect( $ldap_host, $ldap_port)
or exit("<p>ERROR: Could not connect to LDAP server</p>");
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
$bind = ldap_bind($connect, $ldap_user, $ldap_pass )
or exit("<p>ERROR: Could not bind to $ldap_host</p>");
$read = ldap_search($connect, $base_dn, $filter, array("sn","givenname","telephonenumber","mobile"))
or exit("<p>ERROR: Unable to read the LDAP server</p>");
$info = ldap_get_entries($connect, $read);
echo '<table>';
echo '<tr><td>Last</td><td>First</td><td>Phone</td><td>Mobile</td></tr>';
for ($i=0; $i<$info["count"]; $i++) {
echo "<tr>";
echo "<td>" . $info[$i]["sn"][0] . "</td>";
echo "<td>" . $info[$i]["givenname"][0] . "</td>";
echo "<td>" . $info[$i]["telephonenumber"][0] . "</td>";
echo "<td>" . $info[$i]["mobile"][0] . "</td>";
echo "</tr>";
}
echo '</table>';
How do I sort the results first on sn then on givenname?
Thanks!
-Striker
I'm a real rookie at PHP. I've done an LDAP query on Active Directory but cannot figure out how to sort the results. Here's what I have so far:
// ====== P R O C E S S ======
$connect = ldap_connect( $ldap_host, $ldap_port)
or exit("<p>ERROR: Could not connect to LDAP server</p>");
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
$bind = ldap_bind($connect, $ldap_user, $ldap_pass )
or exit("<p>ERROR: Could not bind to $ldap_host</p>");
$read = ldap_search($connect, $base_dn, $filter, array("sn","givenname","telephonenumber","mobile"))
or exit("<p>ERROR: Unable to read the LDAP server</p>");
$info = ldap_get_entries($connect, $read);
echo '<table>';
echo '<tr><td>Last</td><td>First</td><td>Phone</td><td>Mobile</td></tr>';
for ($i=0; $i<$info["count"]; $i++) {
echo "<tr>";
echo "<td>" . $info[$i]["sn"][0] . "</td>";
echo "<td>" . $info[$i]["givenname"][0] . "</td>";
echo "<td>" . $info[$i]["telephonenumber"][0] . "</td>";
echo "<td>" . $info[$i]["mobile"][0] . "</td>";
echo "</tr>";
}
echo '</table>';
How do I sort the results first on sn then on givenname?
Thanks!
-Striker