Take a look at this:

<?php

        $result = mysql_query();
        while ( $data = mysql_fetch_array($result) ) {
                $pnumber=$data["Pnumber"];
                $ourdata[$pnumber][]=$data;
        }

        echo "<pre>";
        foreach ( $ourdata as $data ) {
                foreach ( $data as $array ) {
                        echo "Username: ".$array[0]."<br>";
                        echo "Pnumber:  ".$array[1]."<br>";
                        echo "sec2:     ".$array[2]."<br>";
                        echo "sec3:     ".$array[3]."<br>";
                        echo "sec4:     ".$array[4]."<br>";
                        echo "sec5:     ".$array[5]."<br>";
                        echo "sec5:     ".$array[6]."<br>";
                        echo "<hr>";
                }
        }
        echo "</pre>";
?>

        

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


Thank you for the response to my question unfortunately your answer just
confused me even more.

Saturday, March 30, 2002, 4:25:40 PM, you wrote:

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

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

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

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


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


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

DSK> Hear is an example of the data in the database

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

DSK>  If you will notice the Pnumber for some are the same and some are
DSK>  different. I what to be able to sort on this number and then when
they
DSK>  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