MySQL Forums
Forum List  »  PHP

Trouble with SUM
Posted by: barlow.65
Date: January 30, 2006 04:40PM

Overview of project - students enter hours for community service jobs as they are completed. Each student will have multiple entries in the database.

What I am trying to do is provide a feature that searches by name, lists the entries for that person, and then sums the hours earned for that particular name at the bottom of the table. The search function is not the issue. I am having trouble getting a sum for a particular set of entries in the db.

Below is the code. Can someone help me?

elseif ($SearchLName) {

//show list after search LAST NAME button

$query = mysql_db_query("dbname", "SELECT lname, fname, class, org, hours, tID,SUM(hours) AS total FROM psf_hours WHERE lname='$lname' ORDER BY hours DESC");

echo "<p>Below is the total hours for the student you searched</p>";

echo "<table border='0' width='700' cellpadding='2' cellspacing='1' bgcolor='#000000' >";
echo "<tr bgcolor='#cccccc'>";
echo "<th>Name</th>";
echo "<th>Class</th>";
echo "<th>Organization</th>";
echo "<th>Hours</th>";
echo "</tr>";

while($result = mysql_fetch_array($query)) {




echo "<td valign='top' bgcolor='#ffffff'>$result[lname], $result[fname]</td>";
echo "<td valign='top' bgcolor='#ffffff'>$result[class]</td>";
echo "<td valign='top' bgcolor='#ffffff'>$result[org]</td>";
echo "<td valign='top' bgcolor='#ffffff'>$result[hours]</td>";
echo "</tr>";

}


echo "<td valign='top' bgcolor='#ffffff' colspan='3>Total Hours</td>";
echo "<td valign='top' bgcolor='#ffffff'>$result[total]</td>";

echo "</tr>";





echo "</table>";

}

Options: ReplyQuote


Subject
Written By
Posted
Trouble with SUM
January 30, 2006 04:40PM
January 31, 2006 12:05AM
January 31, 2006 08:24AM
February 01, 2006 04:50AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.