代码点火器选择结果数组


codeigniter select result array

我正在尝试从codeigniter框架中的数据库中选择数据。

我的控制器

public function GetNewestPointers() 
{
  $user_last_login= $this->api_model->getUserLastLogin();
  $result = $this->api_model->getNewestPointers($user_last_login);
  if ($result) 
  { 
    $status = "1";
    $msg = "SUCCESS";
  } 
  else
  {
    $status = "0";
    $msg = "ZERO_RESULT";
  }
  $output = array(
    'status' => $status,
    'message' => $msg,
    'result' => $result
  );
  jsonOutput($output);
} 

我的型号

public function getNewestPointers($user_last_login) 
{
    $query = $this->db->query("select * from `pointer_info` where `create_date`> '$user_last_login'");
    return $query->result_array();
}
public function getUserLastLogin() 
{
    $userId = $this->input->get_post('userId');
    $query = $this->db->query("select * from `users` where `id` = '$userId'");
    if ($query->num_rows() == 0)
        return "0";
    else
        return $query->row('last_login');
}

我当前的流程输出是

"status":"1",
"message":"SUCCESS",
"result":[
    {
        "id":"15",
        "title":"Test Pointer Title",
        "upload_by":"53",
        "create_date":"1413901780",
        "current_status":"approved"
    },
    {
        "id":"14",
        "title":"Test Pointer Title",
        "upload_by":"53",
        "create_date":"1413901750",
        "current_status":"approved"
    }
]

但我不需要使用上面的结果"id":"14"从另一个表中选择数据

并且需要像一样在"item_list"中显示第二个查询数据

"status":"1",
"message":"SUCCESS",
"result":[
    {
        "id":"15",
        "title":"Test Pointer Title",
        "upload_by":"53",
        "create_date":"1413901780",
        "current_status":"approved",
         "item_list":[
                {
                    "id":"138",
                    "name":"test",
                    "picture":"",
                    "purchase_status":"no",
                    "total_quantity":"25"
                },
                {
                    "id":"139",
                    "name":"New name2",
                    "picture":"",
                    "purchase_status":"no",
                    "total_quantity":"1"
                }
            ]
    }
] 

这是我的示例代码,我希望它能有所帮助。

public function GetNewestPointers() 
{
  $user_last_login= $this->api_model->getUserLastLogin();
  $result = $this->api_model->getNewestPointers($user_last_login);
  if ($result) 
  { 
    $status = "1";
    $msg = "SUCCESS";
  } 
  else
  {
    $status = "0";
    $msg = "ZERO_RESULT";
  }
  // sample code
  foreach ($result as $data) 
  {
    $item_list = $this->api_model->getIdData($data['id']);
    $result[$data['id']]['item_list'] = $item_list;
  }
  $output = array(
    'status' => $status,
    'message' => $msg,
    'result' => $result
  );
  jsonOutput($output);
}