Using AVG function
Moderator: General Moderators
-
warriors2003
- Forum Commoner
- Posts: 38
- Joined: Wed Mar 24, 2004 7:24 pm
<?php
$h = $row['hSum']; // ills code
$ab = $row['abSum'];
//this can be anywhere on the page after the mysql_fetch_array cause the fetch_array helps point the row grabbing
// the code you have:
echo "<tr bgcolor=\"$color\"><td><b>$row[avgAvg]</b></td><td><b>$row[hSum]</b></td><td><b>$row[abSum]</b></td><td><b>$row[hrSum]</b></td><td><b>$row[rbiSum]</b></td><td><b>$row[rSum]</b></td><td><b>$row[doublesSum]</b></td><td><b>$row[triplesSum]</b></td><td><b>$row[sbSum]</b></td>"; // ends your echo, but not your table
echo "<td><b>$h/$ab; </b></td></tr>"; // the new echo that incorperates in your table with ills variable.
?>
Thanks again for trying to help!!
$h = $row['hSum']; // ills code
$ab = $row['abSum'];
//this can be anywhere on the page after the mysql_fetch_array cause the fetch_array helps point the row grabbing
// the code you have:
echo "<tr bgcolor=\"$color\"><td><b>$row[avgAvg]</b></td><td><b>$row[hSum]</b></td><td><b>$row[abSum]</b></td><td><b>$row[hrSum]</b></td><td><b>$row[rbiSum]</b></td><td><b>$row[rSum]</b></td><td><b>$row[doublesSum]</b></td><td><b>$row[triplesSum]</b></td><td><b>$row[sbSum]</b></td>"; // ends your echo, but not your table
echo "<td><b>$h/$ab; </b></td></tr>"; // the new echo that incorperates in your table with ills variable.
?>
Thanks again for trying to help!!
-
warriors2003
- Forum Commoner
- Posts: 38
- Joined: Wed Mar 24, 2004 7:24 pm
-
warriors2003
- Forum Commoner
- Posts: 38
- Joined: Wed Mar 24, 2004 7:24 pm
HOLY GEESE!!! I GOT IT!! Don;t know how i pulled it off,,,prolly with alot of luck!!!
I added this to the bottom of Ill's code
$row[avg] = $row['hSum']/$row['abSum'];
<?php
$h = $row['hSum']; // ills code
$ab = $row['abSum'];
$row[avg] = $row['hSum']/$row['abSum'];
Then just used a regular echo with a row being [avg]
THAT SEEMED TO DO IT!!! Thanks guys!!!
I added this to the bottom of Ill's code
$row[avg] = $row['hSum']/$row['abSum'];
<?php
$h = $row['hSum']; // ills code
$ab = $row['abSum'];
$row[avg] = $row['hSum']/$row['abSum'];
Then just used a regular echo with a row being [avg]
THAT SEEMED TO DO IT!!! Thanks guys!!!
-
warriors2003
- Forum Commoner
- Posts: 38
- Joined: Wed Mar 24, 2004 7:24 pm
You guys were right all along!!! I wouldn;t have been able to get it anywhere close to figure out if it wasnt for you guys!!!
But one quick question....I remember you helped me with the rounding function in the sql yesterday, but since the parameters have now changed in the code, i've been palying around with it and can't get it to round,,,again..lol.
This is what you gave me yesterday
"SELECT SUM(h) as hSum, round(avg(Avg), 3) as avgAvg blah blah
And that worked!!!
But now the paramter has changed to just "avg" and its not in the database somethign I can select, its a total i put math work too,,,,,,it might have to be moved to be rounded somwhere else in the code,,,,cause I tried changing the above code a million different ways to fit avg, can't get it to round!!!
Any thoughts??
But one quick question....I remember you helped me with the rounding function in the sql yesterday, but since the parameters have now changed in the code, i've been palying around with it and can't get it to round,,,again..lol.
This is what you gave me yesterday
"SELECT SUM(h) as hSum, round(avg(Avg), 3) as avgAvg blah blah
And that worked!!!
But now the paramter has changed to just "avg" and its not in the database somethign I can select, its a total i put math work too,,,,,,it might have to be moved to be rounded somwhere else in the code,,,,cause I tried changing the above code a million different ways to fit avg, can't get it to round!!!
Any thoughts??
well look at the other thread, you'll get it.
hint: you wont use the sql version provided by wierdan =]
also, php.net is your bible.
http://www.php.net/manual/en/function.round.php
hint: you wont use the sql version provided by wierdan =]
also, php.net is your bible.
http://www.php.net/manual/en/function.round.php
-
warriors2003
- Forum Commoner
- Posts: 38
- Joined: Wed Mar 24, 2004 7:24 pm
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
you dont ahve to use $row['avg'] to assign that to, you can jsut assing it to $avg.
Code: Select all
$avg = $hSum / $abSum;