This topic is locked

Percentage in brackets

8/19/2007 2:25:51 PM
PHPRunner General questions
M
mmponline author

I have 2 fields: greens and gir in my list page.
I want to show the percentage of the one related towards the other with an expression without using a seperate field (maybe using the "Insert PHP code snippet" in visual editor ????):
Eg. greens: 15 gir: 10 Percentage 75%
Thanks for any help.

J
Jane 8/20/2007

Stephan,
you can do it editing SQL query on the Edit SQL query tab.

Here is a sample:

select

greens,

gir,

(gir/greens)*100 as Percentage

from TableName

M
mmponline author 8/20/2007

Thanks Jane, this work just fine. 1 Question however:
I use the average total at the end. What can be done to omit 0 value.
Eg.

1/2 50%

1/3 33.3%

0/0 %

3/4 75%
when calculating the Average of above, it must not calculate the 3rd. Thus the average must be on 3 instead of 4 entries.

M
mmponline author 8/22/2007

Any idea on how to ignore the 0/0 in the average calculation?

J
Jane 8/22/2007

Stephan,
you can do it using BeforeProcessList, BeforeShowList and BeforeProcessRowList[b/] events on the [b]Events tab.

Here are the samples:

function BeforeProcessList(&$conn)

{

global $summa,$cc;

$sum = 0;

$cc = 0;

}
function BeforeProcessRowList(&$data)

{

global $summa,$cc;

$sum += $data["FieldName"];

if ($data["FieldName"])

$cc++;

return true;

}
function BeforeShowList(&$smarty,&$templatefile)

{

global $sum,$cc;

$smarty->assign("showtotal_UnitsInStock",$sum/$cc);

}

hfg 9/7/2007

Is there a way to apply this same concept to a Report?
I tried the following under Report Page Before process:
global $summa,$cc;

$sum = 0;

$cc = 0;

}

function BeforeProcessRowReport(&$data)

{

global $summa,$cc;

$sum += $data["A_C_PREC"];

if ($data["A_C_PREC"])

$cc++;

return true;
and then on the Report Page: Before display I put:
global $sum,$cc;

$smarty->assign("showtotal_A_C_PREC",$sum/$cc);
I get an error when I run the report Error Type 2, Error description Division by zero
Thanks