Re: Arrays and MySQL

From: Date: Sun, 02 Mar 2003 22:49:37 +0000
Subject: Re: Arrays and MySQL
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-137807@lists.php.net to get a copy of this message
On March 2, 2003 01:53 pm, Jason Wong wrote: > On Sunday 02 March 2003 23:34, Beauford.2002 wrote: > > Hi, > > > > I have an array which I am trying to total but having some > > problems. Any help is appreciated. > > > > Example: This is a hockey team and there are 20 players - I am > > selecting the goals, assists, and points from each player and > > then want to have a grand total of all goals, assists, and > > points. > > > > $query = "select goals, assists, points from roster"; > > > > while ($line = mysql_fetch_row($result)) { > > > > $totals[] = $line; > > > > } > > > > I want to total $totals[0][4] through $totals[19][4], > > $totals[0][5] through $totals[19][5], etc. for each stat. I > > thought of putting them in a for loop and just adding them, but > > this seemed kind of messy and the long way around > > You can use array_sum(). What about "SELECT SUM(Goals), SUM(assists)"? Leo

« previous php.general (#137807) next »