This topic is locked

I would like to total hrs and update a field

3/20/2015 2:20:24 PM
PHPRunner General questions
author

I need to sum total hrs for set of classes.
I have 3 tables conference attendees, class list, with hrs per class, and class attendees.
I simply want to total the class attendees hrs spent in all of the classes they go to
attendee ID 45 goes to
class 1 3.75 hrs

class 2 4.25 hrs
Total hrs for attendee ID 45 is 8.0 hrs
I want to total these and have it edit/update a field in the table conference attendees - attendee ID 45
I found this on another post but I'm not sure what to do with it

__
global $conn;

$sql = "select hrs from class_attendees where id='".postvalue("editid1")."'";

$rs = db_query($sql,$conn);

$data = db_fetch_array($rs);

if(!$data)

return;

echo "<table>";

while(1)

{

echo "<tr>";

foreach($data as $v)

{

echo "<td>";

echo htmlspecialchars($v);

echo "</td>";

}

echo "</tr>";

if(!($data = db_fetch_array($rs)))

break;

}

echo "</table>";

mperry622 3/23/2015



I need to sum total hrs for set of classes.
I have 3 tables conference attendees, class list, with hrs per class, and class attendees.
I simply want to total the class attendees hrs spent in all of the classes they go to
attendee ID 45 goes to
class 1 3.75 hrs

class 2 4.25 hrs
Total hrs for attendee ID 45 is 8.0 hrs
I want to total these and have it edit/update a field in the table conference attendees - attendee ID 45
I found this on another post but I'm not sure what to do with it

__
global $conn;

$sql = "select hrs from class_attendees where id='".postvalue("editid1")."'";

$rs = db_query($sql,$conn);

$data = db_fetch_array($rs);

if(!$data)

return;

echo "<table>";

while(1)

{

echo "<tr>";

foreach($data as $v)

{

echo "<td>";

echo htmlspecialchars($v);

echo "</td>";

}

echo "</tr>";

if(!($data = db_fetch_array($rs)))

break;

}

echo "</table>";


You may want to adjust your select statement to sum these two fields and output as a total column.
select Hours1, Hours2, Hours1 + Hours2 as [Total Hours] Where EmployeeID = attendant ID (i am way off but giving example.) reply back and ill help. :-)
This would return two columns of hour data and one column called total with the sums of each. You can narrow it down to only sum alike ID's

501414 3/23/2015

Thank you Mikeperry for the help.
I think I'm making this more difficult. All I want is to total 1 columns worth of class hrs for each conference attendee and then post that to another table.
If I do a search for a particular conference attendee and I have the hrs column set to total it looks perfect.

HJB 3/23/2015

Adding single values to totals per attendee ID is usually an ideal job for the built-in report tool where you can fine-tune searches on per ID basis via advanced search function with ease. This would totally free you from manual coding issues and would deliver the wished result via onboard report feature. Finally I guess that the report option CROSS-TAB INDEXED would perfectly fit to your need while the LIST VIEW one with cumulative results could do fine as well.