How can you use the SUM of the column in other element calc in the same list?

If you mean the sum of all rows in a list for a given element, like this. You could add a where clause if you wanted to.

Code:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('sum('.$db->quoteName('column_name').')');
$query->from($db->quoteName('#__table_name'));

$db->setQuery($query);
$result = $db->loadResult();

return $result;
 
You can use placeholders in code, don't forget to put them in single quotes if they are for string values.
 
You can use placeholders in code, don't forget to put them in single quotes if they are for string values.

It's best to use quotes even for values you expect to be numbers, in case they are empty. And if necessary, cast them appropriately ...

Code:
$foo_int = (int)'{mytable___some_integer}';
$foo_float = (float)'{mytable___some_decimal}';

That way, if the placeholder is empty, you get 0 rather than a syntax error, as the resulting code being eval'ed is ...

Code:
$foo_int = (int)'';

... which yields 0, rather than ...

Code:
$foo_int = ;

... which is an error.

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

Thank you.

Members online

No members online now.
Back
Top