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

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



Doug

Sorry if I am thick, but where does the sort write the data to?

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.

When I list $info after the sort I get 0=107 and 1 to 107 = array.

The code I am using is 

<?php { 
               $ds=ldap_connect("localhost"); 
                      if ($ds) 
                            $r=ldap_bind($ds); 
                       	$justthese = array ("sn", "givenname); 
                       	$sr=ldap_search($ds,"dc=xxx,dc=yy","sn=*"); 

                       	$info=ldap_get-entries($ds,$sr); 

				print "no of records to be sorted =".$info["count"];
                       	function EntryCompare(&$a,&$b) 
                       		{ 
                       			$sortfield = "sn"; 
							if (!is_array($a))
								return -1;
							elseif (!is_array($b))
								return 1;
							              								
							if($a[$sortfield][0]==$b[$sortfield][0]) 
                      					 { 
                       					return 0; 
                       				} 

                       			if($a[$sortfield]>$b[$sortfield]) 
                       				{ 
                       					return 1; 
                       				} 
                       			else 
                      					 { 
                       					return -1; 
                       				} 
                      			 } 


 	                  	usort($info,EntryCompare); 
					while (list($key,$value)=each ($info))
							{ echo "$key: $value\n";}
 
			print "no of records in the sorted file =".$info["count"];
                       for ($i=0, $i<$info["count"]; $i++) 
      	                 { 
           		            echo statement 
                       	} 

Thanks for your help so far

Tony
> 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
> only.
> 
> 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
> 



----------------------------------------------------------------
 
  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