Coding help needed in calc plugin

masa12

New Member
Can someone help me and make one sample code for calc plugin ? My javascript coding skill?s is pretty much Level noob.
I have form where I have to sum values from repeat group and one field what is in main form.
Field?s are { deb_pokalista_5_repeat___Paino} and {deb_pokalista___Lentajan_paino} both field are integer
I debugged $data array and get this data from there
Code:
[deb_pokalista_5_repeat___Paino_raw] => Array(
[0] => 95
[1] => 100
)
And using this example I got this far, but there it end?s.
Code:
// Replace these two lines with your element's values
$joinId = '4';
$fullElementName = 'deb_pokalista_5_repeat___Paino';
// $vals is an array - it contains values of either 0 (not selected) or other
 
$vals = $data['join___' . $joinId . '___' . $fullElementName];
So I was hoping that someone who has better coding skill?s could help here.
the result's what I need is about {deb_pokalista___Lentajan_paino} + { deb_pokalista_5_repeat___Paino} + ect...
thanks in advance




 
Hi,

Try a calc element with something like this (probably in it's own group outside your repeating group):

PHP:
$numbers = explode(',', "{table___repeating group_field}");
for ($i=0; $i < count($numbers); $i++) {
  $total += $numbers[$i];
}
return $total;

Dale
 
Thank you.
I appreciate help, it do what it should do. Calculate how many fields are in repeat group and return that value.
But my idea is get value of those field and calculate them and adding calculation outside repeat group
Code:
// Repeat group data
[deb_pokalista_5_repeat___Paino_raw] => Array
        (
            [0] => 81
            [1] => 89
        )
// Field is outside of repeat group
{deb_pokalista___Lentajan_paino}
// Something like this
{deb_pokalista___Lentajan_paino} +[0] +[1] = ?
I'll think that This "sum-repeating-values-on-a-form" thread is same problem.
But at least now I?m getting some data out form repeat group to work with, still would be more than grateful little push to right direction...
 
Add a CALC element to the form outside the repeating group and use the code above to populate it. The code above should add all the repeat values and return the sum. If that code is the value for a CALC element outside the repeat, that CALC element should contain the total.
 
My bad. It's working like it should. I messed up something in morning when i look it up.
I owe you big one.
but code here if it help someone in future.
Code:
$numbers = explode(',', "{deb_pokalista_5_repeat___Paino_raw}");// repeat group
for ($i=0; $i < count($numbers); $i++) {
  $total += $numbers[$i];
}
return $total + (int)'{deb_pokalista___Lentajan_paino}'; // one field calculated outside repeat group
 
Still looking some coding help, I have following code and it works pretty well. but I just have figure out how to update database, $total to Piikki (account balance) field in deb_hyppaajat.
I have tried update , set and insert but i'm only getting plank page, thinking i have some syntax prob. So if someone can help me on this i'd be more than grateful... again..

Code:
$verdi = '{fab_ostokset___Nimi_raw}'; //dabase join from deb_hyppaajat table
$db = JFactory::getDbo();
$query= "SELECT Piikki FROM deb_hyppaajat WHERE id = " . $db->quote($verdi); //select Piikki Field (account balance)
$db->setQuery($query);
$price = $db->loadResult();
$total = (int)$price - '{fab_ostokset___Yhteensa}'; // calculate shopping total from account balance
return $total;
 
Hi Alll... Please help me
I have a database (price_db) which contains colums : user_id(raw), and price. etc...
how to sum the colum of price according to the user_id?
and how to display it in my web?
please help me...
 
You may want to start a new thread for this since it's a separate question...

But based on what you are asking your best bet is probably the php form plugin at http://fabrikar.com/forums/index.php?wiki/php-form-plugin/ and of course you would have to write the code based on the specifics of your site and data.

It also sounds like you may want someone to write the code for you and display it, which is not likely to happen via standard forum posts. If that's what you want you may want to request someone to do it for you which would require you giving them access to your site and possibly paying them. If that is what you want - post a new thread and ask for that.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top