Calculations on Selected Items

My application has a Service Request page. Everything is set-up for selecting the service options. Now it needs to reflect the selected items in the side column to give a total Job Estimate… as the items are selected.

The serviceItem table is populated with a timeEstimate for each itemName.

The jobClass table is populated with the hrRate for each className. So, the rate/hr depends on the job classification.

There is a prepared html table in the side column to hold the information, I do not know 1) How to reflect the selections in the side as they are selected and 2) How to do the calculations on the selected items .

The selectable items are in activeListBox, multiple selection, and are posted to the serviceRequest table as a comma seperated string.

The time for each item doesn’t have to display, just the total time of the selected items

<TABLE summary="This table represents the estimated charges for services selected on the Service Request Form. Total estimated time multiplied by the hour rate.">

<CAPTION>Service Estimate</CAPTION>


   <TH id="t1">Items</TH>

   <TH id="t2">Time Est.</TH>


   <TD headers="t1">itemName itemName ...</TD>

   <TD headers="t2">totalTime</TD>


   <TH id="t1">Hour Rate</TH>

   <TH id="t2">Total</TH>


   <TD headers="t1">hrRate</TD>

   <TD headers="t2">T*hR=x</TD>



I really could use some guidence… I have searched and read and tried but fail :(

This is the model code for getting the selected items into the db and it works. But I can’t get it to echo into the prepared table.

	/*  for activeListBox */

	public $selection;

	public $listBoxData;

		//explode your db column named selection and put result into your virtual as comma seperated string */

	public function afterFind()



			return true;


	/*implode your selection */

	public function beforeSave()



			return true;


The code below produces the PHP Error - Use of undefined constant selection - assumed ‘selection’ . And if I put the $ with selection it says it is an undefined variable.

<?php echo $ServiceRequest->model($ServiceRequest,selection) ;?> 

I have tried creating a function but no luck. I did at one point have the first item appear but it wasn’t even selected!! <please help>