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

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



On 24 May, Antonin Novak wrote:
> Sorry if I am thick, but where does the sort write the data to?

It is sorted in place (the result is in the $info array).
 
> I have been trying to get the script you sent me to work, with no joy.
> I have 107 entries in my selection, but when I sort them my $info 
> ends up with no records.
> 
> I have printed the $a[sortfield][0] and the $b[sortfield][0] in the 
> various "if statements" and get nothing.
should have been $a[$sortfield][0] (php won't complain about this)
 
> When I list $info after the sort I get 0=107 and 1 to 107 = array.

This is correct. Because of the is_array tests, the "count" element is
sorted to the top of the list ($info[0] = 107). Then, each successive
element is an array of attributes. Each attribute is an array of
values. When you print an array in php it will output "Array".

These are the same mistakes as before, I'm not sure where they are from
but I'll point them out this time.
 
>                        	$justthese = array ("sn", "givenname); 
Missing a quote
>                        	$info=ldap_get-entries($ds,$sr); 
Should be ldap_get_entries
>  	                  	usort($info,EntryCompare); 
after the sort, element 0 is the old "count" parameter. You cannot
reference it by ["count"] since a usort remove the association. YOu
could us a uasort but the would also keep the association of each
value, which means you could not access each element in sorted order
via an index. You could by using the each or next functions.
> 					while (list($key,$value)=each ($info))
> 							{ echo "$key: $value\n";}
Here you are printing the array itself, not the values. If you want a
complete dump of information, you need to do something like

  while (list($key,$value)=each ($info))
  {
    if (!is_array($value))
      echo "$key: $value<br>\n";
    else
    {
      echo "$key:<br>\n";
      while (list($attribute_key, $attribute_value) = each($value))
      {
        if (!is_array($attribute_value))
          echo "- $attribute_key: $attribute_value<br>\n";
        else
        {
          echo "- $attribute_key:<br>\n";
          while (list($value_key, $value_value) = each($attribute_value))
          {
            echo "- - $value_key: $value_value<br>\n";
          }
        }
      }
    }
    echo "<br>\n";
  }

> 			print "no of records in the sorted file =".$info["count"];
You can't use ["count"] anymore. Use [0].
>                        for ($i=0, $i<$info["count"]; $i++) 
>       	                 { 
>            		            echo statement 
>                        	} 

I don't know where statement comes from. What I had was

  // 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");
  }

-- 
Doug Nazar
Dragon Computer Consultants Inc.
Tel: (416) 708-1578     Fax: (416) 708-8081