Alex,

> Thanks, but I'm still stuck! on a page using mysql how do I use the
query
> you gave me in a page?
> this is my code now but it wont show the total groundballs, how do I
make it
> add up the sum of all the rows then output it onto the page for me?
>
> <?php
> $db = mysql_connect("db", "****", "***");
> mysql_select_db("net3dual_lax",$db);
> $search = mysql_query("SELECT SUM(groundballs) FROM rahs");
> while($num=mysql_fetch_array($search)) {
> printf ("Total groundballs: %s",$num["groundballs"]);
> }
> ?>


The problem here is how MySQL returns values. Try executing the query in
the MySQL client. See what the column heading is? This 'heading' is also
the name that PHP picks up and requires you to use in the resultant
associative array. So $num["SUM(groundballs)"] might work, but I don't
like your chances for getting away with that approach every time!

Check out MySQL column name aliases - they change the column heading AND
the PHP associative array key, eg:

SELECT SUM(groundballs) AS groundpounders FROM rahs
...
printf ("Total groundballs: %s",$num["groundpounders"]);

Regards,
=dn



> > SELECT SUM(groundballs),  SUM(shots) FROM table_name;
> > Also check out this:
> > SELECT SUM(groundballs),  SUM(shots) FROM table_name GROUP BY team;
> >
> > On Sat, 2 Mar 2002 16:33:08 -0600, Alex Behrens said:
> >
> > > Hey Guys & Gals,
> > >
> > >  I'm rather new to mysql and need some help accomplishing a
command for
> my
> > >  site:
> > >
> > >  I am looking to take a column in my table and add all the values,
they
> are
> > >  all numerical. how do I do this? Below is an example of my table:
> > >
> > >
>
+-----------------+--------+------+---------+-------------+-------+-----
----
> > >  -----+---------------+------------+
> > >  | name            | number | team | penalty | groundballs | shots
|
> > >  faceoffs_won | faceoffs_lost | date       |
> > >
>
+-----------------+--------+------+---------+-------------+-------+-----
----
> > >  -----+---------------+------------+
> > >  | pete nelson     |     29 | V    | none    |           7 |    17
|
> > >  4 |             3 | 2002-03-01 |
> > >  | darrenolson     |     91 | V    | none    |          13 |    32
|
> > >  2 |             1 | 2002-03-02 |
> > >  | vanguildertest4 |     17 | V    | none    |           5 |    15
|
> > >  1 |             1 | 2002-03-01 |
> > >
>
+-----------------+--------+------+---------+-------------+-------+-----
----
> > >  -----+---------------+------------+
> > >
> > >  I want to add all of the values for the groundballs, shots, and
> faceoffs,
> > >  how do I make it add up row values?


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to