We have now opened a commercial services section here on the forum for registered users. If you have a Fabrik project that you wish to have someone work on for you, post it under Help Wanted. If you are an application developer and wish to earn some money helping others, post your details under Fabrik Application Developers.
Both of these are unmoderated. It will be up to both parties to work out the details and come to an agreement.
For running J!5.1 you must https://fabrikar.com/forums/index.php?wiki/update-from-github/ or include the new file manually https://fabrikar.com/forums/index.php?threads/joomla-5-1-and-fabrik-cannot-find-files-error.54473/post-285151 See also Announcements
Hugh, do I need to add all three sets of code or only the last portion?In general, to handle an array of values you want to match in a query, you use IN() rather than =, and "implode" the array into a comma seperated list. The PHP explode() and implode() functions are very useful, allowing you to 'explode' a delimited string (i.e. list of numbers separated by commas) into an array, or implode an array into a delimited string.
So an array of integers can be imploded into a comma separated string with implode(',', $service), which will produce a string like "1,2,3,4,5". Which can then be used in the IN() part of the query.
Like this:
Code:$db->setQuery("SELECT duration_total FROM services WHERE id IN(" . implode(',', $service) . ")");
Also ... when doing straight forward summing, quicker and easier to let MySQL do that rather than doing it in PHP ...
Code:$db->setQuery("SELECT SUM(duration_total) AS total FROM services WHERE id IN(" . implode(',', $service) . ")");
Also ... although not required, it's good to get in the habit of building queries using the "query builder" syntax. Not so important for simple queries like this, but a definite advantage when you start getting in to building more complex queries.
Code:$query = $db->getQuery(true); $query->select('SUM(duration_total) AS total ') ->from('services') ->where('id IN(' . implode(',', $service) . ')'); $db->setQuery($query); $calc = $db->loadResult();
NOTE - this assumes $service is numbers (which it is). When dealing with an array of string you want to use in an IN(), you have to go through another step to quote the strings.
-- hugh
Just the last, I was showing you progressively better ways of doing the same thing.Hugh, do I need to add all three sets of code or only the last portion?
$service = $formModel->formData['jobcard___services_raw'];
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('SUM(duration_total) AS total ')
->from('services')
->where('id IN(' . implode(',', $service) . ')');
$db->setQuery($query);
$calc = $db->loadResult();
$formModel->updateFormData('jobcard___test_duration', $calc, true);