[PHP] Pulling data into an array and sorting

2002-03-30 Thread rdkurth


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.122YES  YES   NO  YES  YES
 Fred  123.345.123YES  YES   NO  YES  YES
 Jone  123.345.124YES  YES   YES  NO  YES
 Tom   123.345.124YES  YES   NO  YES  YES
 Frank 123.345.123YES  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




RE: [PHP] Pulling data into an array and sorting

2002-03-30 Thread Demitrious S. Kelly

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.122YES  YES   NO  YES  YES
 Fred  123.345.123YES  YES   NO  YES  YES
 Jone  123.345.124YES  YES   YES  NO  YES
 Tom   123.345.124YES  YES   NO  YES  YES
 Frank 123.345.123YES  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




Re[2]: [PHP] Pulling data into an array and sorting

2002-03-30 Thread rdkurth


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.122YES  YES   NO  YES  YES
DSK  Fred  123.345.123YES  YES   NO  YES  YES
DSK  Jone  123.345.124YES  YES   YES  NO  YES
DSK  Tom   123.345.124YES  YES   NO  YES  YES
DSK  Frank 123.345.123YES  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,
 rdkurthmailto:[EMAIL PROTECTED]


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




RE: Re[2]: [PHP] Pulling data into an array and sorting

2002-03-30 Thread Demitrious S. Kelly

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.122YES  YES   NO  YES  YES
DSK  Fred  123.345.123YES  YES   NO  YES  YES
DSK  Jone  123.345.124YES  YES   YES  NO  YES
DSK  Tom   123.345.124YES  YES   NO  YES  YES
DSK  Frank 123.345.123YES  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,
 rdkurthmailto:[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