[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: Sorting output to be returned to a HTML page using PHP

On 23 May, Antonin Novak wrote:
> Doug
> I have also posted this on  a PHP mailing list , but to date they 
> have not been able to help me.
> I have tried your amendment but I am still getting the same error 
> message.

I should have looked a bit deeper. There are several issues with what
you are trying to do. I'm assuming the syntax errors are in the email

ldap_get_entries returns a 3-dimensional array of all entries
from that query. The first dimension is each entry and it also contains
a "count" member. There is no key to sort on here. If you are trying to
sort all returned entries and then display them, try something like
the attached file. Note that it needs a bit more error checking (i.e.
what if the entry doesn't have that attribute) for production usage.

Doug Nazar
Dragon Computer Consultants Inc.
Tel: (416) 708-1578     Fax: (416) 708-8081
  if ($ds)
  $justthese = array ("sn", "givenname");

  function EntryCompare(&$a,&$b)
    $sortfield = "uid";

    if (!is_array($a))
      return -1;
    elseif (!is_array($b))
      return 1;

    if ($a[$sortfield][0] == $b[$sortfield][0])
      return 0;
    elseif($a[$sortfield][0] > $b[$sortfield][0])
      return 1;
      return -1;

  usort($info, EntryCompare);

  // start at 1 to skip count
  for ($i=1; $i<count($info); $i++)
    print($info[$i]["dn"] . "<br>\n");
    print("-- " . $info[$i]["uid"][0] . "<br>\n");