This topic is locked
[SOLVED]

  Calculate a percentage from two fields 5.2

6/23/2010 3:34:10 PM
PHPRunner General questions
S
spbryantusa author

I need to calculate a percentage from two fields and have it show on the list page
Register (this is the field in the database that has the number of people registered for an event)

Attended (this is the field in the databse that has amount actually attended the event)

Attendance_Rate (this the field I need to post the percentage automatically)
ANY HELP WOUDL BE GREAT!!

T
tekhead2004 6/23/2010

advance to the editor screen. View the list page that has these fields. find the Attendance_Rate field, and double click it. on the view as tab, do custom.
then do something like:

$value = ($data["Register"]/$data["Attended"])*100; //this takes the register column and divides it by the attened column, then multiplies to get a percent out of 100

//$value is what actually displays on the page


if you want to display a percent sign with it do something like this:

$total = ($data["Register"]/$data["Attended"])*100;

$value = $total."%"

//this does the same as above, but appends a % sign


if you need to round the number off you can do something like this:

$total = ($data["Register"]/$data["Attended"])*100;

$value = round($total,2)."%" //where 2 is the digit you want to round to

//this does the same as above, but appends a % sign
Sergey Kornilov admin 6/24/2010

Theoretically speaking you only need two fields here. Third field can be calculated on the fly.
Example:
select

Registered,

Attended,

100*Attended/Registered as Attendance_Rate

from ...
You can make this change on SQL Query screen in PHPRunner.