Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2003
    Posts
    1

    Unanswered: 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...

  2. #2
    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/
    --

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •