User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » Ernie's perpetual mysql/php help thread Page [1]  
Ernie
All American
45943 Posts
user info
edit post

so i've got a table that looks something like this:


+-------+---------+---------+---------+
| NAME | FIELD_1 | FIELD_2 | FIELD_3 |
+-------+---------+---------+---------+
| BOB | 1 | 1 | 1 |
+-------+---------+---------+---------+
| BOB | 2 | 2 | 2 |
+-------+---------+---------+---------+
| SAM | 3 | 3 | 3 |
+-------+---------+---------+---------+
| SAM | 4 | 4 | 4 |
+-------+---------+---------+---------+
| JOE | 5 | 5 | 5 |
+-------+---------+---------+---------+
| JOE | 6 | 6 | 6 |
+-------+---------+---------+---------+


i have a simple php script that prints that table out de facto, no problem

what i would like to do is print out the column sums for each NAME

i.e.:


+-------+---------+---------+---------+
| NAME | FIELD_1 | FIELD_2 | FIELD_3 |
+-------+---------+---------+---------+
| BOB | 3 | 3 | 3 |
+-------+---------+---------+---------+
| SAM | 7 | 7 | 7 |
+-------+---------+---------+---------+
| JOE | 11 | 11 | 11 |
+-------+---------+---------+---------+


how do i do this

4/10/2006 10:39:27 PM

HaLo
All American
14263 Posts
user info
edit post

in the sql query, use a select sum() and group by

ie.

SELECT SUM(field_1), SUM(field_2), SUM(field_3)
GROUP BY name;

then printout the results generated from this query

note: this is pseudocode. i have no clue if the syntax is correct



[Edited on April 11, 2006 at 1:14 AM. Reason : .]

4/11/2006 1:13:47 AM

 Message Boards » Tech Talk » Ernie's perpetual mysql/php help thread Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.