I am using PHP v 3.0.16 on a Unix 6.22 server running RedHat 1.3.12.
We use OpenLDAP to store staff details and use PHP to search this database and display the results on our intranet.
I have a problem in sorting the output in alphabetical order in one of my scripts.
The script searches the database, depending upon the parameter(s) input via a form.
If no matches are found it displays an error message.
If only 1 match is found it displays the output in a predefined form.
If more than 1 match is found it displays the information in a table, so the user can select the record they require full details of. This information is displayed in the order it is stored in the database and not alphabetical.
I have tried to sort the output so that it displays the results in alphabetic order based on surname.
My code to search the database is:
$ds=ldap_connect("localhost");
if ($ds)
{
$r=ldap_bind($ds);
$sr=ldap_search($ds,"dc=cca,dc=cz",$PARAM);
$info = ldap_get_entries($ds, $sr);
ldap_close($ds);
My code to sort the information is:
echo " The number of records before the sort = ".$info["count"]."<br>";
function snCompare(&$a ,&$b)
{
$snfield = ("cn");
if (!is_array($a))
return -1;
elseif (!is_array($b))
return 1;
if $a[$snfield][0]==$b[$snfield][0])
return 0;
if ($a[$snfield][0]>$b[$snfield][0])
return 1;
}
usort($info,snCompare);
echo " The number of records after the sort = ".$info["count"]."<br>";
The number of records before the sort is 7 but the number of records after the sort is 0.
I have used the same code in another script which searchs the database based on surname and displays the information in alphabetic order. ie. the last parameter in the ldapseach line is sn=* instead of $PARAM.
can anyone please help me. The answer is probably straing me in the face but I cannot see it.
Thanks in advance
Tony