Calc value stored in db

dimoss

Well-Known Member
Hi

I have set a calc element with 'Only Calc On Save' to NO in order to calc on the fly but not store into the db.
However the value is stored into the db after the form submission.
Any ideas?

My settings are:
Selection_037.png

Thanks!
 
Calc is stored always.
The difference
'Only Calc On Save'=yes --> calc is stored on form submission, but NOT calculated in list view or details view but taken from DB
'Only Calc On Save'=no --> calc is stored on form submission but always recalculated in list and details view (so the DB value doesn't matter);

I don't know if e.g. calc in a filter or sum/avarage... of calc are calculating on the fly or taking DB values (I never used it).
 
Hi Troester

Thanks for the reply and the explanation :)
However I have another calc element in the same form with the same settings but different calc code which never stored in the db!
Can you explain this?
Thanks!
 
Can you explain this?
No:D (Maybe I'm totally wrong and there has been a change in 3.1 which I don't know; or something in your calc code is preventing stroring)
 
Hi Troester

This is the calc code for the element I wrote before:

Code:
$a = (int)'{fab_cbd___tournament_raw}';
$b = '{fab_cbd___assoc1_raw}';
$c = '{fab_cbd___assoc2_raw}';
$d = '{fab_cbd___name1_raw}';
$e = '{fab_cbd___name2_raw}';
$id = (int)'{fab_cbd___id_raw}';
$wl_rmv = '{fab_cbd___wl_remove_raw}';
 
$query1 = "SELECT id FROM fab_cbd WHERE tournament = $a AND assoc1 = '$b' AND assoc2 = '$c'";
$db = & JFactory::getDBO();
$db->setQuery( $query1 );
$user = $db->loadColumn();
 
$query2 = "SELECT organizer FROM fab_tournaments WHERE id = $a";
$db = & JFactory::getDBO();
$db->setQuery( $query2 );
$xx = $db->loadResult();
 
$query3 = "SELECT wl_cd FROM fab_tournaments WHERE id = $a";
$db = & JFactory::getDBO();
$db->setQuery( $query3 );
$wl = $db->loadResult();
 
sort($user, SORT_NUMERIC);
$keyz = array_search($id, $user);
 
if (($keyz > 0) && ($xx != $b) && ($xx != $c) && ($d != '') && ($e != '') && ($wl != 'Yes') && ($wl_rmv != 'Yes'))
{return 'WL';}
else if (($keyz < 1) && ($xx != $b) && ($xx != $c) && ($d != '') && ($e != '') && ($wl != 'Yes') && ($wl_rmv != 'Yes'))
{return '';}
else if (($keyz > 5) && ($xx == $b) && ($xx == $c) && ($d != '') && ($e != '') && ($wl != 'Yes') && ($wl_rmv != 'Yes'))
{return 'WL';}
else
{return '';}

Anyway it doesn't matter..-:)
 
As usual, the only way to work out why something doesn't work is to start dumping out your variables and exiting, making sure you are picking up the right values.

Typically, in any code of more than a few lines, I recommend not using placeholders, and instead either use $formModel->getElementData(), or access $formModel->formData[] directly. Especially if you are dealing with any knd of join element, and raw values, as those are likely to be arrays when the form is submitted.

-- hugh
 
Thanks Hugh!
It's not a big deal actually because either way the calculation is correct when viewing the records on the list.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top