php - How to select username in a given query in Joomla?
321
Helllo,
I have my own Joomla table and I select everything from it to json_encode the result. How can I manipulate some fields in $db->loadObjectList()? I need username from #__users for a given userId.
Here's my code:
<?php
$query = $db->getQuery(true)
->select('*') // fields a and b from this table are userIds
->from('#__my_custom_table');
$db->setQuery($query);
$result = $db->loadObjectList();
/* how can I select the username from #__users where #__my_custom_table.a and .b is like #__users.id to add these information to $result
I want to override these fields from #__my_custom_table: a, b
*/
foreach ($result as $row) {
$row->a = JFactory::getUser($row->a)->name;
// how to override this in $result?
}
echo json_encode($result, JSON_FORCE_OBJECT);
Answer
Solution:
Something like this: