This topic is locked

Calculations

1/4/2008 11:33:12 AM
PHPRunner General questions
T
tomcio author

Hi All,

I am new to PHP and MySQL and have following problem. I will be grateful if someone could help.

In my table I have fields: TotalTime, Rate and ProfitCost.

On Add and Edit the following calculationshould take place:
ProfitCost=TotalTime*Rate
ProfitCost format - "0000.00", TotalTime format - "0000", Rate format "0.00".
Although the calculation is simple I have tried everything I could think of and I am getting weird results.

Nothing as it should be when done by hand.

What data format or definition do I need to use?
TotalTime is calculated prior as TotalTime=Time+12.
Here is the syntax:
// Parameters:

// $values - Array object.

// Each field on the Add form is represented as a 'Field name'-'Field value' pair

// $where - string with WHERE clause pointing to record to be edited

// $oldvalues - Array object with existing data record content

// $keys - Array object with added record key column values
//** Custom code ****

// put your custom code here
$values["ClientName"]=strtoupper($values["ClientName"]);

$values["ClientSurname"]=strtoupper($values["ClientSurname"]);

$values["Address1"]=strtoupper($values["Address1"]);

$values["Address2"]=strtoupper($values["Address2"]);

$values["City"]=strtoupper($values["City"]);

$values["PostCode"]=strtoupper($values["PostCode"]);

$values["CaseStage"]=strtoupper($values["CaseStage"]);

$values["EndCode1"]=strtoupper($values["EndCode1"]);

$values["EndCode3"]=strtoupper($values["EndCode3"]);
$values["TotalTime"]=$values["Time"]+12;
$values["ProfitCost"]=$values["TotalTime"]*$valued["Rate"];
return true;
// return true if you like to proceed with adding new record

// return false otherwise
Please, please help.
Tom

A
alang 1/6/2008

You don't say what the actual problem is. It would also help if you could say for each of the numeric fields, what datatype has been specified in MySQL and what format you have them set to in the visual editor tab in PHPR. Suggest using DECIMAL 10,2 for ProfitCost and Rate. Is the following line right?
$values["ProfitCost"]=$values["TotalTime"]$valued["Rate"];
or did you mean:
$values["ProfitCost"]=$values["TotalTime"]
$values["Rate"];