Using select max(fieldname) in a calc element

mirceat

Member
Hello,

I really don't know what i'm doing wrong here. I want to use a calc element to retrieve the max value of an element and return the value. So i wrote a simple query:

PHP:
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query
    ->select('MAX('.$db->quoteName('grupeaza_optiune').')')
    ->from($db->quoteName('contracte_setari_6_repeat'))
    ->where($db->quoteName('parent_id')." = 26");
$db->setQuery($query);
$result = $db->loadResult();
return $result;

The query is returning the correct result when i run it directly in database:

SELECT MAX(`grupeaza_optiune`) FROM `contracte_setari_6_repeat` WHERE `parent_id` = 26

return: 5

But using the calc element is showing 1 instead of 5..and i don't know why :(

For testing, the calc element is set to "calc on load" but i will need to use "Ajax Calculation". Please note that the calc element is in a repeat group.

Thank you
 
Hmm. Don't know. 'Calc on load' only works if you have AJAX enabled.

Try putting some debug in there, like ...

var_dump((string)$query);exit;

... just before the loadResult, and make sure the query looks sane.

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

Thank you.

Members online

Back
Top