array in calc element

elle

Member
Hi there,

I have a repeated group in my form. In there are four elements, whom doing a db query to get their values per ajax. I think, these four querys make the loading of the site a bit lame. The eval php function looks like this:
PHP:
$geraet = {0_gpa_abrechnung_19_repeat___2_geraet_vk_raw};
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('dirEUR')->from('gpa_proviliste')->where('id =' . $geraet);
$db->setQuery($query);
return $db->loadResult();
In all these four elements are nearly the same query, with the differences, that they ask for other fields in the database. The other fields are "dirProz", "parEUR" and "parProz". What I thought is, to make ONE query with ALL fields in there in ONE element like this:
PHP:
$geraet = {0_gpa_abrechnung_19_repeat___2_geraet_vk_raw};
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('dirEUR,dirProz,parEUR,parProz')->from('gpa_proviliste')->where('id =' . $geraet);
$db->setQuery($query);
$result = $db->loadResult();
return $result[0];
...and let return the other fields in the other elements just with a simple
PHP:
return $result[1];
PHP:
return $result[2];
PHP:
return $result[3];

How can I do this?

Thanks for your interrest an your help.
Kind regards
--Elle--
 
Well, that's kind of tricky, as any solution would have to work on both the client side, and on the server when submitting.

One approach might be to do it with some custom Javascript in a form JS file, although it wouldn't be trivial. Not super hard, but a but tricky. Change the elements form calcs to read only fields, and a function that makes an AJAX call to the server with all the 2_geraet_vk values, gets the results and updates all the repeats in one go. You'd have to run it onLoad, plus whenever a group was added, or your vk value got changed in any of the groups.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top