Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SUM of All Columns

Status
Not open for further replies.
Joined
Jun 9, 2004
Messages
188
Location
US
Hello I know this is probably one of the worst Query's you have every seen. I need some help because I really dont think this is right even though it works.

I am trying to find the sum of all my column in my mysql db.
Fields are hits at bats third base ....etc and I have an empty Average field that i play on doing hits/at bats =average.

This is my code:
Code:
$result = mysql_query("SELECT SUM( h ) , SUM( ab ) , SUM( sb ) , SUM( tb ) , SUM( hr ) , SUM( bb ) , SUM( r ) , SUM( rbi ), SUM(h)/SUM(ab) 
 FROM stats");
	
	
	$rs1=mysql_fetch_row($result);
 
     $div_value = $rs1[8];
     $average=sprintf("%.3f",$div_value);
	 
	 echo"$average <br>" ;

     echo "Total hit:  $rs1[0] <br>
	   Total AB:   $rs1[1] <BR>
                       $rs1[2] <br>
		       $rs1[3] <br>
		       $rs1[4] <br>
		       $rs1[5] <br>
		       $rs1[6] <br>
		       $rs1[7] "; 


?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top