This topic is locked

Sum of field on list page??

2/10/2009 4:49:00 PM
PHPRunner General questions
U
Urnso author

Is it possible to gather the sum of multiple fields from the list page and display it?
I have a field "duration" that tells the user how long they have been working on a project. At the end of the day I would like to show them a total of that field.
Currently I have the users going to Advanced search and selelcting the date and searching by their name. This will bring up just their entries for that date.
Could array_sum() be used somehow in the list page after record processed?

T
thesofa 2/11/2009

you should be able to select Totals for each /any/all columns on the PHPR list building page

U
Urnso author 2/11/2009

you should be able to select Totals for each /any/all columns on the PHPR list building page


Couldn't find that anywhere. I think that may be with reports and charts. I remember seeing that option there.
I have this working:
[codebox]global $conn,$userid;

$sql = "select Duration, SUM(Duration) AS SumDuration from timesheets where Name='".$_SESSION["UserID"]."' Group by Name";

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

$data = db_fetch_array($rs);
echo $data["SumDuration"];[/codebox]
What this does is calculate their total hours forever, How can I force that query to only select the records from today?
I tried where statement like AND Date = now() but I think the time is throwing it off because it wouldn't work. Any ideas?
Thx!

U
Urnso author 2/11/2009

[codebox]global $conn,$userid;

$sql = "select Date, Duration, SUM(Duration) AS SumDuration from timesheets where Name='".$_SESSION["UserID"]."' AND Date = '".date("Y-m-d")."' Group by Name";

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

$data = db_fetch_array($rs);
echo "<strong>Hours Worked Today: </strong>";

echo $data["SumDuration"];[/codebox]
Ok, the above code works for each user.
is there a way to tie this into the advanced search where after a search is done it will caculate only the values on that page?
lets say a manager logs in and uses adavnced search to look up 2009-02-11 and the name smith.
how can I do this using the variables passed from advanced search?

U
Urnso author 2/12/2009

Jane,
any ideas on how to tie this with the advanced search?

J
Jane 2/13/2009

Hi,
you can set up total for Duration field on the Fields order and totalstab in PHPRunner.

U
Urnso author 2/17/2009

Jane,
Worked perfect as usual....
Now have anotehr questions. I have a field that is totaled called Duration and another totaled that is Quatity.
The duration is in hours and Quatity is in impressions. I would like to divide the Totaled Quatity by Totaled Hours to give me and impressions per hour figure.
Can this be done?
Would it be some like:
$Quatity_total / $Duration_totap = $impressions

echo "Your impressions per hour is:"

echo $impressions
Is there a guide to what all the controls are called? Something that tells us what each field on the page is called under code.
for instance:
readonly field on add/eddit is referred as $readonlyfields under code.

text box and other controls are called $control_fieldname
you may have this somewhere but i couldn't locate in the help maybe looking in wrong place.
Thx!

J
Jane 2/18/2009

Hi,
use custom event for this purpose.

Here is a sample:

global $xt;

$impressions = $xt->xt_getvar("Quatity_total")/$xt->xt_getvar("Duration_total");

echo $impressions;

U
Urnso author 2/18/2009

Jane,
This one isn't working for me. Here's my code on List Page:Before Display:
[codebox]global $xt;

$tduration = $xt->xt_getvar("Duration_total");

$tquantity = $xt->xt_getvar("Quantity_total");
if ( $tquantity == "0" ){

$impressions = "None";

echo $impressions;

} elseif ( $tquatity != "0" ){

$impressions = $xt->xt_getvar("Quantity_total")/$xt->xt_getvar("Duration_total");

echo $impressions;

}else {

echo "";

}[/codebox]
Any idea why this wouldn't work?
If I just do
[codebox]echo $xt->xt_getvar("Duration_total");

echo $xt->xt_getvar("Quantity_total");

[/codebox]
I get nothing. When on the page the totals are clearly there. Am I adding this in the wrong place?

J
Jane 2/19/2009

Sorry for my fault.

Here is the correct code:

global $record;

$impressions = $record["Quatity_total"]/$record["Duration_total"];

echo $impressions;