I've written a script to populate certain fields on the fly (see this thread). This script achieves what I want it to:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select('AVG(bc) AS value_sum')
->from($db->quoteName('#__cck_store_item_content'))
->where($db->quoteName('actionheld')." = ".$fields['art_id']->value);
$db->setQuery($query);
$result = $db->loadResult();
$result = round($result);
$fields['bc_avg']->value = $result;
Since I need about 20 of these calculations I've tried to come up with a script that cycles through arrays holding components of the calculations and field names I want to use. However, I can't get the below script to work:
$db = JFactory::getDbo();
$calc = array( "SUM", "AVG", "MAX", "MIN" );
$fieldcalc = array ( "total", "avg", "max", "min" );
$stats = array( "bc", "s5", "fsk", "ex", "ga", "sb" );
$i = 0;
$j = 0;
while ( $i <= 3 ):
while ( $j <= 5 ):
$query = $db->getQuery(true);
$query
->select("'".$calc[i]."(".$stats[j].") AS value_sum'")
->from($db->quoteName('#__cck_store_item_content'))
->where($db->quoteName('actionheld')." = ".$fields['art_id']->value);
$db->setQuery($query);
$result = $db->loadResult();
$result = round($result);
$fields["'".$stats[j]."_".$fieldcalc[i]."'"]->value = $result;
$j++;
endwhile;
$i++;
endwhile;
Between php syntax, Joomla syntax, SEBLOD syntax and MySQL syntax I am not exactly sure where I am going wrong. Any ideas?