This topic is locked

Implementing custom COUNT function on the List page

2/20/2012 4:31:37 PM
PHPRunner Tips and Tricks
Sergey Kornilov admin

Question:
I have a column that has "Yes", "No" and "na" values. I need to COUNT (or TOTAL ??? ) only the "Yes" values from the column in the "List page".
If I use COUNT from the "Fields order and totals" section of PHPRunner, I get a count of all of the values (including "No" and "na"), which isn't what I need. How do I get a count of only the "Yes" values?
Answer:

  1. Turn on totals on the field in question ('Totals' screen)
  2. Proceed to Visual Editor and click on the yellow rectangle that will display totals for this field. Switch to HTML mode to find the variable name. If field name is Make you will see something like {$make_total}
  3. Add the following code to 'List page: Before process' event

$_SESSION['mycount']=0;


4. 'List page: Before record processed' event

if ($data["make"]=='Yes')

$_SESSION['mycount']++;


5. In 'List page: Before display' event use the following code:

$xt->assign("make_total",$_SESSION['mycount']);


This is it. Make sure to replace make with the actual field name.