This topic is locked

sum value

4/28/2012 5:58:58 PM
PHPRunner General questions
swami author

How i should do as fly calculation of total amount from value "amount" ?
thanks for support .

swami author 4/29/2012



Check this article: http://xlinesoft.com/phprunner/docs/how_to_calculate_values_on_the_fly.htm


yes i have tried .. get error message .
Parse error: syntax error, unexpected '<' in C:\Users\Administrator\Documents\PHP\account\output\include\phpfunctions.php on line 543
i have only amount and the total_amount field , and want to get sum value of amount .
well i have also tried put the same filed as it shows in document and still get same error message.?
thanks .

C
cgphp 4/29/2012

The code of the above article is for a "Javascript on load" event.

swami author 4/29/2012



The code of the above article is for a "Javascript on load" event.


yes i have put on add page as over javescript OnLoad event ..

C
cgphp 4/29/2012

Please, post your code.

swami author 4/29/2012



Please, post your code.


thank you Cristian, here is the code as i put

var ctrlPrice = Runner.getControl(pageid, 'amount');

var ctrlQuantity = Runner.getControl(pageid, 'quantity');

var ctrlTotal = Runner.getControl(pageid, 'total_entrate');



function func() {

if ( ctrlPrice.getValue()!='' && ctrlQuantity.getValue() && !isNaN(ctrlPrice.getValue()) && !isNaN(ctrlQuantity.getValue()))

ctrlTotal.setValue(parseFloat(ctrlPrice.getValue()) * parseFloat(ctrlQuantity.getValue()));

else

ctrlTotal.setValue('');

};



ctrlPrice.on('keyup', func);

ctrlQuantity.on('keyup', func);
C
cgphp 4/29/2012

The code looks correct. Something is wrong elsewhere. Please post the code of the following file
C:\Users\Administrator\Documents\PHP\account\output\include\phpfunctions.php
from line 530 to line 550.

swami author 4/29/2012



The code looks correct. Something is wrong elsewhere. Please post the code of the following file
C:\Users\Administrator\Documents\PHP\account\output\include\phpfunctions.php
from line 530 to line 550.


here we go...

$message="<<< "."Record was NOT added"." >>>

".$errstr;

$readavalues=true;

$error_happened=true;

}
// return custom expression

function CustomExpression($value,$data,$field,$table="")

{

global $strTableName;

if(!$table)

$table=$strTableName;

if($table=="entrate" && $field=="total_entrate")

{

<?php

$result = mysql_query("total_entrata, name FROM uscita");

$row = mysql_fetch_array($result, MYSQL_NUM);

array_sum($row);

?> ;

}

return $value;

}
C
cgphp 4/29/2012

Please, edit the code in PHPrunner and remove the opening <?php tag before

$result = mysql_query("total_entrata, name FROM uscita");


and remove the closing ?> ; tag after

array_sum($row);
swami author 4/29/2012



Please, edit the code in PHPrunner and remove the opening <?php tag before

$result = mysql_query("total_entrata, name FROM uscita");


and remove the closing ?> ; tag after

array_sum($row);



thanks Cristian , i did it as you show me .. and now it show no error but there is no value in total_entrate ..??
well strange thing going on ... i have looked again php file and i find only this

// return custom expression

function CustomExpression($value,$data,$field,$table="")

{

global $strTableName;

if(!$table)

$table=$strTableName;

return $value;

}
// return lookup wizard WHERE expression

function LookupWhere($field,$table="")

{

global $strTableName;

if(!$table)

$table=$strTableName;

return "";

}
// return lookup wizard WHERE expression

function GetDefaultValue($field,$table="")

{

global $strTableName;

if(!$table)

$table=$strTableName;

return "";

}


it seems the change did not happened or it throw it out .. so no wonder there is no value there in total_entrate ?? how it is possible ??

C
cgphp 4/29/2012

total_entrate or total_entrata ?
Make sure your fields name are correct.

C
cgphp 4/29/2012

Please, post the code of the "View as custom" field you have on the list page.

swami author 4/30/2012



Please, post the code of the "View as custom" field you have on the list page.


sorry Cristian , i making you crazy ..but what to do ..

Now i restart the PHPrunner and i get back again this error :

Parse error: syntax error, unexpected T_VAR in C:\Users\Administrator\Documents\PHP\account\output\include\phpfunctions.php on line 543


here is in phpfunction the line

// return custom expression

function CustomExpression($value,$data,$field,$table="")

{

global $strTableName;

if(!$table)

$table=$strTableName;

if($table=="entrate" && $field=="total_entrate")

{

var ctrlPrice = Runner.getControl(pageid, 'amount');

var ctrlQuantity = Runner.getControl(pageid, 'quantity');

var ctrlTotal = Runner.getControl(pageid, 'total_entrate');



function func() {

if ( ctrlPrice.getValue()!='' && ctrlQuantity.getValue() && !isNaN(ctrlPrice.getValue()) && !isNaN(ctrlQuantity.getValue()))

ctrlTotal.setValue(parseFloat(ctrlPrice.getValue()) * parseFloat(ctrlQuantity.getValue()));

else

ctrlTotal.setValue('');

};



ctrlPrice.on('keyup', func);

ctrlQuantity.on('keyup', func);;

}

return $value;

}


and the last on list view as custom

var ctrlPrice = Runner.getControl(pageid, 'amount');

var ctrlQuantity = Runner.getControl(pageid, 'quantity');

var ctrlTotal = Runner.getControl(pageid, 'total_entrate');



function func() {

if ( ctrlPrice.getValue()!='' && ctrlQuantity.getValue() && !isNaN(ctrlPrice.getValue()) && !isNaN(ctrlQuantity.getValue()))

ctrlTotal.setValue(parseFloat(ctrlPrice.getValue()) * parseFloat(ctrlQuantity.getValue()));

else

ctrlTotal.setValue('');

};



ctrlPrice.on('keyup', func);

ctrlQuantity.on('keyup', func);


thanks for ongoing investigation and support !!!!!

C
cgphp 4/30/2012

Please, check firebug for errors.