sorting - How to group by categories in LDAP using PHP

250

How to group or arrange the results in LDAP according to "ou". OU have 4 or more categories and display it properly. How to do this with PHP and HTML? Please help me. I'm new in LDAP

OU example

   ou=web service
   ou=department
   ou=city

How to do display the result like this?

   sn     dn                                        mail                 ou
   user   cn=user,ou=web service,dc=domain,dc=com   [email protected]   web service
   sn     dn                                        mail                 ou
   user   cn=user,ou=department,dc=domain,dc=com   [email protected]    department 

Here's the PHP array

  $dn = 'dc=domain,dc=com';
  $filter = "(|(sn=$person*)(fullname=$person*))";
  $ldaparray = array ("ou", "sn", "fullname", "mail");
  $sr=ldap_search($ldapconn, $dn, $filter, $ldaparray);
  $info = ldap_get_entries($ldapconn, $sr);
  echo "<pre>";
  print_r ($info);
  echo "</pre>";

Output using print_r

Array
(
[count] => 1409
[0] => Array
    (
        [sn] => Array
            (
                [count] => 1
                [0] => user
            )

        [0] => sn
        [count] => 1
        [dn] => cn=username,ou=web service,dc=domain,dc=com
    )
[1] => Array
    (
        [sn] => Array
            (
                [count] => 1
                [0] => user
            )

        [0] => sn
        [mail] => Array
            (
                [count] => 1
                [0] => [email protected]
            )

        [1] => mail
        [count] => 2
        [dn] => uid=userid,ou=department,dc=doamin,dc=com
    )

People are also looking for solutions to the problem: PHP - Get raw image data from image in a HTML document

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.