Run a while loop on your data and pull it into an array....

Heres an example (though this pulls from a text file the idea is the
same...) Hope this helps...

<?php
 // READING THE DATA
function read_data($datafile) {
        $data=file($datafile);
        foreach ( $data as $line ) {
                $temp=explode(':', $line);
                $cp=$temp[4];
                $return[$cp][]=$line;
        }
        if ( is_array($return) ) {
                return($return);
        } else {
                return("NULL");
        }
}
?>

<?php
 // USING THE DATA              
        $hosts=read_data('./hosts.dat');
        if ( $hosts != 'NULL' ) {
                $count=0;
                foreach ( $hosts as $host ) {
                        $temp=explode(':', $host[0]);
                        $hostss.=str_replace("%%COMPANY%%",
decode($company=$temp[4]),$template_company_begin);
                        foreach ( $host as $hst ) {
                                $temp=explode(':', $hst);
                                $h_names[]=$temp[0];
                                $hostss.=str_replace("%%DISPLAY%%",
display_host($hst, $count),
$template_company_mid);
                                $count++;
                        }
                        $hostss.=$template_company_end;
                }
        } else { 
                $hosts="No Hosts In Database...<br>";
        }
?>


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
Sent: Saturday, March 30, 2002 4:22 PM
To: php
Subject: [PHP] Pulling data into an array and sorting


I need to pull data into and array from a mysql database and then sort
that data according to one of the fields and then print it to the
screen.

Hear is an example of the data in the database

username     Pnumber     sec2 sec3 sec4 sec5 sec6
 Gary      123.345.122    YES  YES   NO  YES  YES
 Fred      123.345.123    YES  YES   NO  YES  YES
 Jone      123.345.124    YES  YES   YES  NO  YES
 Tom       123.345.124    YES  YES   NO  YES  YES
 Frank     123.345.123    YES  YES   NO  YES  YES

 If you will notice the Pnumber for some are the same and some are
 different. I what to be able to sort on this number and then when they
 are printed they would be printed according to this number in groups

  

-- 
Best regards,
 rdkurth                          mailto:[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to