If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
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, 20: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, 21: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

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