Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > MySQL > Adding mysql results together

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-08-03, 21:50
globalhec globalhec is offline
Registered User
 
Join Date: Dec 2003
Posts: 1
Adding mysql results together

I'm sure this has been answered a million times before, but I can't seem to find a clear concinse answer.

I need to do two things.
First I need to get the results from a mysql database and add them together. Example: I need to retrieve the credit worth of several courses a student has taken.
Here is the code I have been trying to use:
[/code]
$getcredits = mysql_query("SELECT credit FROM courseactivity WHERE sid='$sid' GROUP BY grade");
$creditsarray = mysql_fetch_array($getcredits);
$totalcredits = array_sum($creditsarray);
echo "total: ".$totalcredits;
[/code]
The next thing I need to do is take all of the grades the student has gotten and get the average.

I'm stumped and need help...
Reply With Quote
  #2 (permalink)  
Old 12-13-03, 22:20
omiossec omiossec is offline
Registered User
 
Join Date: Jan 2003
Location: Paris, France
Posts: 320
First you should use an agredate function for doing the first query

SELECT sum(credit) FROM courseactivity WHERE sid='$sid' GROUP BY grade

For the second you should post your table definition
__________________
Olivier Miossec
--
http://www.lasso-developpeur.net/
--
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On