Ok guys I'm trying to incorporate a table with some totals of baseball stats of all the players on a particular team. I have some nice player breakdowns, but need to figure out a way to just total a query and select a partical team then be able to display a little table with their totals. If this is what i use for the team, how would a put the particual math work for each cateogry?? I'm good with make work in submit forms but suck outside of it. Just some basic adding would work for now, if i can figure out just one total i can then figure out the math work for other complex categories such as avg.
Here is what I have:
<?
$query = mysql_query("select * from pit where team = 'Ana'");
?>
<?
$color = "#CCCCCC";
while ($row = mysql_fetch_array($query))
{
echo "<tr bgcolor=\"$color\"><td><b><img src=$row[logo]height=28 width=33</td><td><font size=2><div align=center><b><a href=pitplayer.php?pit_id=$row[pit_id]>$row[pitname]<b>$row[w]</b></td><td><font size=2><div align=center><b>$row[l]</b></td><td><font size=2><div align=center><b>$row[s]</b></td><td><font size=2><div align=center><b>$row[k]</b></td><td><font size=2><div align=center><b>$row[IP]</b></td><td><font size=2><div align=center><b>$row[ER]</b></td><td><font size=2><div align=center><b>$row[era]</b></td></tr>";
?>
------------------------
Th above code is what I use just for the filetring in the players. But i figure if i can learn to add the totals code and math work to it. I just don;t know how to go about it.
Would I put the math work in the Echo?? Or before it? And how would i change the query around if needed? I'm thinking I just need to add the math work probably to the echo???
Thanks in Advance
Help with a math function total
Moderator: General Moderators
-
warriors2003
- Forum Commoner
- Posts: 38
- Joined: Wed Mar 24, 2004 7:24 pm
-
compound_eye
- Forum Newbie
- Posts: 15
- Joined: Wed Mar 17, 2004 8:42 pm
mysql will actually do a lot of these sort of things for you
SELECT SUM(homeRuns) as runSum, AVG(homeRuns) as runAvg
FROM `player`
WHERE team ='Ana'
will give you the average and the total home runs scored by the team
i'd like to explain more but it's pretty late at night where i am and i need to go to sleep
good luck
SELECT SUM(homeRuns) as runSum, AVG(homeRuns) as runAvg
FROM `player`
WHERE team ='Ana'
will give you the average and the total home runs scored by the team
i'd like to explain more but it's pretty late at night where i am and i need to go to sleep
good luck
-
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
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
See if this helps:
Code: Select all
$sql="SELECT SUM(homeruns) as runSum, AVG(homeruns) as runAvg FROM players WHERE team='Ana'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
echo $row['runSum'];
echo "<BR>";
echo $row['runAvg'];-
warriors2003
- Forum Commoner
- Posts: 38
- Joined: Wed Mar 24, 2004 7:24 pm
yes that worked!!!! thanks you so much!!! Now Im trying to incorporate that in some standard tables I have. It doesn;t work in that, but I think cuase i messed up the result query,,this is what I have,,what is wrong do you think???
<?
$sql="SELECT SUM(hr) as hrSum FROM hit WHERE team='Ana'";
?>
<body bgcolor="#000000">
<TABLE>
<tr>
<td bgcolor="#C4ECFF"><b>HR</b> </a> </td>
</tr>
<?
$color = "#CCCCCC";
while ($row = mysql_fetch_array($result))
{
echo "<tr bgcolor=\"$color\"><b>$row[hrSum]</b></td></tr>";
if($color == "#CCCCCC") {
$color = "#FFFFFF";
} else {
$color = "#CCCCCC";
}
}
?>
-----------------------
Yours works i tested it,,just trying to fill in the blanks with what im trying to use,,,thanks!!!
<?
$sql="SELECT SUM(hr) as hrSum FROM hit WHERE team='Ana'";
?>
<body bgcolor="#000000">
<TABLE>
<tr>
<td bgcolor="#C4ECFF"><b>HR</b> </a> </td>
</tr>
<?
$color = "#CCCCCC";
while ($row = mysql_fetch_array($result))
{
echo "<tr bgcolor=\"$color\"><b>$row[hrSum]</b></td></tr>";
if($color == "#CCCCCC") {
$color = "#FFFFFF";
} else {
$color = "#CCCCCC";
}
}
?>
-----------------------
Yours works i tested it,,just trying to fill in the blanks with what im trying to use,,,thanks!!!
-
warriors2003
- Forum Commoner
- Posts: 38
- Joined: Wed Mar 24, 2004 7:24 pm
I GOT IT TO WORK!!! Thanks so much guys!!! It was my bad,,my html tables were all jacked up...lol..
Anyways,,can you guys direct me to a sight with the math functions??? Cuase I'm going to need more complex functions,,
for instance,,,for avg. i'll need to make a function that adds sum ofl "h" dividing by the sum "ab". I imagine that will be complex, but I it should be able to be pulled off right?
Anyways,,can you guys direct me to a sight with the math functions??? Cuase I'm going to need more complex functions,,
for instance,,,for avg. i'll need to make a function that adds sum ofl "h" dividing by the sum "ab". I imagine that will be complex, but I it should be able to be pulled off right?