Sum function
| From: | Claudia | Date: | Sun, 18 Feb 2001 20:27:55 +0000 |
| Subject: | Sum function | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-40466@lists.php.net to get a copy of this message | ||
I am looking for code that explains how to sum a value in a database based
on a current field retrieved from the database.
Example:
query = "select course_name, course_build, milestone, testcase, time_tested,
issue_status, comment,
bug_number, tested_by, date_tested from testissues where test_issue_id =
$viewid";
$result = mysql_query( $query );
1 - retrieve needed fields from database based on the id the user links from
($viewid)
2 - assign the course_name value from the query statement to a variable to
be used on html page
Assign: $course_name = mysql_result( $result, 0, "course_name" );
Use variable: print " <td><font color =
#006666><b>$course_name</b></font></td>\n";
Now I would like to sum ALL the time_tested values in my database WHERE the
course_name =
$course_name (the variable retrieved for the record)
query = "select sum(time_tested) where course_name = $course_name";
$result = mysql_query( $query );
$total_time = mysql_result( $result, 0, "sum(time_tested)");
First issue -- php does not seem to recognize the value of $course_name
Second issue -- will the $total_time value be calculated correctly based on
the above syntax?