2016-05-30 16 views
0

Helllo,如何在Joomla中的給定查詢中選擇用戶名?

我有我自己的Joomla表,我選擇從它到json_encode的結果。我如何操作$ db-> loadObjectList()中的某些字段?我需要#__users的用戶名作爲給定的userId。

這裏是我的代碼:

<?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); 

回答

0

事情是這樣的:

$query = $db->getQuery(true) 
      ->select('t.*, u.username') 
      ->from('#__my_custom_table t') 
      ->join('LEFT', '#__users u ON t.a = u.id'); 
相關問題