Re: [PHP] Arrays and MySQL

2003-03-02 Thread Beauford.2002
> You can use array_sum().

I have used that in the past, but only on single arrays, I can't figure out
how to do on multi-level arrays, and since I need to have different totals
from different levels of the array, I don't think this will work. If you can
shed some light on this it would be appreciated.

>From below - $totals[0][4] through $totals[19][4] , $totals[0][5] through
$totals[19][5], etc.


- Original Message -
From: "Jason Wong" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, March 02, 2003 4:53 PM
Subject: Re: [PHP] Arrays and MySQL


> 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().
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.biz
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
> --
> Search the list archives before you post
> http://marc.theaimsgroup.com/?l=php-general
> --
> /*
> Man's unique agony as a species consists in his perpetual conflict between
> the desire to stand out and the need to blend in.
> -- Sydney J. Harris
> */
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and MySQL

2003-03-02 Thread Leo Spalteholz
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and MySQL

2003-03-02 Thread Jason Wong
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().

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Man's unique agony as a species consists in his perpetual conflict between
the desire to stand out and the need to blend in.
-- Sydney J. Harris
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and MySQL

2003-03-02 Thread Beauford.2002
It gets a little more complicated than this. There are several teams (each
with 20 players) and then there is the team owner and then there is the
player position, etc.  So to do this I would have to do some kind of a join
and so on - and to date haven't been able to figure this out with sums. I
would also have to do a second query (I am already doing one to get the
points for each player), so I might as well just use it and through the
results in an array and then total it from there - and thus my question of
how I total the array


- Original Message -
From: "Marek Kilimajer" <[EMAIL PROTECTED]>
To: "Beauford.2002" <[EMAIL PROTECTED]>
Cc: "PHP General" <[EMAIL PROTECTED]>
Sent: Sunday, March 02, 2003 11:10 AM
Subject: Re: [PHP] Arrays and MySQL


> Cannot you just make MaSQL count it?
>
> $query = "select sum(goals), sum(assists), sum(points) from roster";
>
>
>
>
> 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
> >
> >Thanks
> >
> >
> >
> >
> >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and MySQL

2003-03-02 Thread Marek Kilimajer
Cannot you just make MaSQL count it?

$query = "select sum(goals), sum(assists), sum(points) from roster";



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
Thanks



 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php