Calc field

Status
Not open for further replies.

aje

Member
Is it possible to have a calc field in a form without storing the value on save ?

I have a form with 6-7 fields and 30-40 calc field. Is it best (fastest) to get the calc values from other calc elements or directly from a db query ?

Another thing i am wondering about if its possible to list many records in a form so that i can use a default value loading from another table to do an auto update on 3-4 elements in 10-15 record with just a couples of clicks ?
 
Is it possible to have a calc field in a form without storing the value on save ?

As far as I know, the answer is "no".

I have a form with 6-7 fields and 30-40 calc field. Is it best (fastest) to get the calc values from other calc elements or directly from a db query ?

You can't rely on a value calculated from a calc element to be used by another calc element because you are never sure of the order these get triggered, so each calc should be able to do its own independant calculation, using placeholders (to non-cal elements) and/or sql queries.

Another thing i am wondering about if its possible to list many records in a form so that i can use a default value loading from another table to do an auto update on 3-4 elements in 10-15 record with just a couples of clicks ?

One form can "accomodate" only one record (because it relies on an unique ID). If you need to update several records at once, you should look to the update_col list plugin. It might do what you need. If not, maybe a PHP list plugin can do the trick.
 
  • Like
Reactions: aje
Thanks you for the feedback :) going to change some of my calc fields. Had done both versions. Shall take a look and test the plugins for the form and see if i find a solution.
 
How can i get 2 or more value out of 1 query and use it in a calculation ?

$verdid1 = '{fab_prislister___pl_stverdier_raw}'; (dropdown)
$db = JFactory::getDbo();
$query= "SELECT `fab_standardverdier`.`prosent_dagtid_beregnet_akkord`, `fab_standardverdier`.`vaule2` FROM `fab_standardverdier` WHERE fab_standardverdier.id = '$verdid1'";
$db->setQuery($query);
$prosfastdag = $db->loadResult();
return (int)$prosfastdag1 * $prosfastdag1;
 
in the form i have and databasejoin(dropdown)

i have alot of calculation i do from the tabel that i have connected with the databasejoin (dropdown element)

I have some calc field i neeed to get several values from the other table. So when i choose one value in the dropdown i need several values out into a calc element. If i do it with more queries it will look like this

$verdid1 = '{fab_prislister___pl_stverdier_raw}'; (dropdown)

$db = JFactory::getDbo();
$query= "SELECT `fab_standardverdier`.`value1` FROM `fab_standardverdier` WHERE fab_standardverdier.id = '$verdid1'";
$db->setQuery($query);
$value1 = $db->loadResult();

$db = JFactory::getDbo();
$query= "SELECT ``fab_standardverdier`.`vaule2` FROM `fab_standardverdier` WHERE fab_standardverdier.id = '$verdid1'";
$db->setQuery($query);
$value2 = $db->loadResult();

return (int)$value1 * $value2
Cant i do this with one query ?
 
You can use only one query using loadObject() instead of loadResult():
PHP:
$verdid1 = '{fab_prislister___pl_stverdier_raw}';
 
$db = JFactory::getDbo();
$query = $db->getQuery( true );
$query->select('value1, value2')->from('fab_standardverdier')->where('id = ' . $db->quote($verdid1));
$db->setQuery($query);
try {
    $value = $db->loadObject();
} catch (Exception $e ) {
   
}
return (int)$value->value1 * $value->value2;

Replace 'value1/value2' by the real name of the database columns.
 
  • Like
Reactions: aje
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top