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);
Something like this:
$query = $db->getQuery(true)
->select('t.*, u.username')
->from('#__my_custom_table t')
->join('LEFT', '#__users u ON t.a = u.id');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.