Forum Moderators: coopster
My latest question deals with variables once again. I have a table with values stored for multiple rows. Example: points scored (value in column) for players (rows) in a table (list of players). If I display a specific (by team, by position, by hair color, etc.) list of players and their points scored, how can i find the sum of their points scored? This should be simple but it is killing me! Because when I extract "pts" (column) as $pts(variable), i cannot get the sum because each $pts overwrites the previous one.
Please keep in mind that i am a humble beginner, so be as specific as possible with your examples. Thanks in advance!
$fgpct = $fgm / $fga;
$f_fgpct = sprintf("%.3f", $fgpct);
echo "$year $fgm-$fga ($f_fgpct)<br>";
}
$getdata = "select * from 200102playerstats where playerid = $activeplayer";
$result = mysql_query($getdata);
while ( $row = mysql_fetch_array($result))
{
extract($row);
$fgpct = $fgm / $fga;
$f_fgpct = sprintf("%.3f", $fgpct);
echo "$year $fgm-$fga ($f_fgpct)<br>";
}
$getdata = "select * from 200203playerstats where playerid = $activeplayer";
$result = mysql_query($getdata);
while ( $row = mysql_fetch_array($result))
{
extract($row);
$fgpct = $fgm / $fga;
$f_fgpct = sprintf("%.3f", $fgpct);
echo "$year $fgm-$fga ($f_fgpct)<br>";
}
I want to total the fgm and fga, in this example. Each year's stats are stored in separate tables.
$storedyrs = array("200001","200102","200203");
$tfgm = 0;
$tfga = 0;
foreach ($storedyrs as $actyr) {
$getdata = "select * from " . $storedyrs . "playerstats where playerid = $activeplayer";
$result = mysql_query($getdata);
while ($row = mysql_fetch_array($result)) {
extract($row);
$fgpct = $fgm / $fga;
$f_fgpct = sprintf("%.3f", $fgpct);
echo "$year $fgm-$fga ($f_fgpct)<br>";
$tfgm += $fgm;
$tfga += $fga;
}
}