Re: sort output of while
| From: | Andy Woolley | Date: | Mon, 05 Aug 2002 18:52:27 +0000 |
| Subject: | Re: sort output of while | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111240@lists.php.net to get a copy of this message | ||
Or better still - why not just sort the query.
"SELECT * FROM scores order by fieldname"
-- Andy
----- Original Message -----
From: "Andy Woolley" <andy@milonic.com>
To: <jim@jimlong.net>; "php" <php-general@lists.php.net>
Sent: Monday, August 05, 2002 7:50 PM
Subject: Re: [PHP] sort output of while
> You can sort arrays with the sort($arrayname); command
>
> Not sure if it will sort arrays from MySQL thought, but I don't see why
not.
>
> Cheers
> Andy
>
>
>
> ----- Original Message -----
> From: "Jim Long" <jim@jimlong.net>
> To: "php" <php-general@lists.php.net>
> Sent: Monday, August 05, 2002 8:39 PM
> Subject: [PHP] sort output of while
>
>
> > Hi,
> > Thanks to everyone who has helped me.. Just a golf coach trying to make
> > my life simpler with this little program.. I got the pages built that
> > load and edit the db. Now I'm working on the display for the team
> members...
> >
> > BTW: The db is loaded with 15 0's where there are no scores updated yet,
> > that's why I have the $i loop.
> >
> > Sor far I have made it work, but can't figure out how to sort it by the
> $rounded_ave
> >
> >
> > // Get the Name and Scores from the db
> > $result = mysql_query(
> > "SELECT * FROM scores");
> > if (!$result) {
> > echo("<P>Error performing query: " .
> > mysql_error() . "</P>");
> > exit();
> > }
> >
> > // Loop -- organize the db output
> > while ( $row = mysql_fetch_array($result) ) {
> >
> > $last_name=$row["last_name"];
> > $first_name=$row["first_name"];
> >
> > // Sets the value of $i with the number of scores that have been updated
> > // BTW: Could not get your simplification to work yet
> > $i=0;
> > $s1=$row[s1];
> > if ($s1!= 0){
> > $i++;
> > }
> > $s2=$row[s2];
> > if ($s2!= 0){
> > $i++;
> > }
> > $s3=$row[s3];
> > if ($s3!= 0){
> > $i++;
> > }
> > $s4=$row[s4];
> > if ($s4!= 0){
> > $i++;
> > }
> > $s5=$row[s5];
> > if ($s5!= 0){
> > $i++;
> > }
> > $s6=$row[s6];
> > if ($s6!= 0){
> > $i++;
> > }
> > $s7=$row[s7];
> > if ($s7!= 0){
> > $i++;
> > }
> > $s8=$row[s8];
> > if ($s8!= 0){
> > $i++;
> > }
> > $s9=$row[s9];
> > if ($s9!= 0){
> > $i++;
> > }
> > $s10=$row[s10];
> > if ($s10!= 0){
> > $i++;
> > }
> > $s11=$row[s11];
> > if ($s11!= 0){
> > $i++;
> > }
> > $s12=$row[s12];
> > if ($s12!= 0){
> > $i++;
> > }
> > $s13=$row[s13];
> > if ($s13!= 0){
> > $i++;
> > }
> > $s14=$row[s14];
> > if ($s14!= 0){
> > $i++;
> > }
> > $s15=$row[s15];
> > if ($s15!= 0){
> > $i++;
> > }
> >
> > // get the average score and round it using $i for the number of scores
> > $available_scores =
> array($s1,$s2,$s3,$s4,$s5,$s6,$s7,$s8,$s9,$s10,$s11,$s12,$s13,$s14,$s15);
> > $gross_score = array_sum($available_scores);
> > $ave_score = ($gross_score / $i);
> > $rounded_ave = number_format($ave_score, 2);
> >
> > // end loop -- varibles $last_name, $first_name, $available, $ave_score
> > // I could just print everthing here but it would not be sorted by
> $rounded_ave
> > // I need to extract these varibles (each loop) and put them in an
> > ordered list with a sorted output
> > }
> >
> > How do I do that?
> >
> > I appreciate the help from this list!
> > Thanks Again,
> > Coach Jim Long
> >
> > --
> > 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