I have a complex query like below. I want the p.ComponentId
values to be the first level keys of the multidimensional result set array. However, it does not work as expected. In my case, when I don't set a key, it returns 12 items in the array as expected. When I nominate a column as the parameter of loadAssocList()
, it only returns one (the last) item.
Am I doing something wrong?
The query is this:
// Get database connector
$db = JFactory::getDbo();
// Prepare query to get all fields
$query = $db->getQuery(true)
->select($db->qn('t.value'))
->from($db->qn('#__rsform_properties', 'p'))
->leftJoin($db->qn('#__rsform_components', 'c').' ON ('.$db->qn('c.ComponentId').' = '.$db->qn('p.ComponentId').')')
->leftJoin($db->qn('#__rsform_translations', 't').' ON (CONCAT('.$db->qn('p.ComponentId').',\'.ITEMS\') LIKE '.$db->qn('t.reference_id').')')
->where($db->qn('c.FormId').'='.$db->q($args['form']->FormId))
->where($db->qn('t.form_id').'='.$db->q($args['form']->FormId))
->where($db->qn('p.PropertyName').'='.$db->q('ITEMS'))
->where($db->qn('c.Published').'='.$db->q(1))
->order($db->qn('c.Order'));
$db->setQuery($query);
// Get all fields
$fields = $db->loadAssocList();
Which returns 12 results just fine.
But when i change the last row to:
$fields = $db->loadAssocList('p.ComponentId');
I get this result:
array(1) {
[""]=>
array(1) {
["value"]=>
string(2) "Ja"
}
}
I also tried t.reference_id
, but this provides the same result.
I was expecting something like this:
array(1) {
["$key"]=>
array(1) {
["value"]=>
string(2) "Ja"
}
}
where $key
would be the row's p.ComponentId
value.