[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: Sorting output to be returned to a HTML page using PHP (SUCCESS)
Doug,
Firstly I must apologise for the typos in my last message ie. the
missing quotes and wrong format of ldap_get_entries. they were
correct in my code.
The problem I had was that I had specified a wrong sortfield,
instead of specifyinh "sn" as per your instructions, I used $info[sn].
I now produce sorted information.
Thanks for all your help. I think/hope I am a little wiser now.
Tony
> 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
----------------------------------------------------------------
Antonin Ch. Novak mailto:Antonin.Novak@cca.cz
Systemovy administrator
Systemova a technicka podpora
CCA spol. s r.o. Web: http://www.cca.cz
Kratka 8,
301 17 Plzen
Czech Republic
Tel: +42 019 7221253
Fax: +42 019 7222931