循环返回一个结果在调节器查询

时间:2018-05-22 07:21:32

标签: php codeigniter-3

我正在尝试从代码点火器中的数据库中获取数据。这个循环只返回一个循环。

$userchatData = $this->db->get($this->db->dbprefix('usres_chat'))->result_array();

 foreach($userchatData as $key => $userdata)
 {
       $userdatas[]= array(
                  'chat_id' => $userdata['chat_id'],
                  'chat_from' => $userdata['chat_from'],
                  'created_date' => $userdata['created_date']
           );
 }
 $data['ChatdatabyId'] = $userdatas;
 $data['responseCode'] = '200';

 $data['responseMessage'] = 'User listing successfully';

 echo json_encode($data);

2 个答案:

答案 0 :(得分:2)

您需要在循环外定义view = inflater.inflate(R.layout.fragment_turboone, null); 。它在循环内部就是为什么它会覆盖数据并返回最后一条记录。

view = inflater.inflate(R.layout.child_layout, null);

答案 1 :(得分:1)

希望这会对你有所帮助:

$userchatData = $this->db->get($this->db->dbprefix('usres_chat'))->result_array();

foreach($userchatData as $key => $userdata)
{
    $userdatas[$key]['chat_id'] = $userdata['chat_id'];
    $userdatas[$key]['chat_from'] = $userdata['chat_from'];
    $userdatas[$key]['created_date'] = $userdata['created_date'];
}

/*print_r($userdatas); output here*/

$data['ChatdatabyId'] = $userdatas;
$data['responseCode'] = '200';

$data['responseMessage'] = 'User listing successfully';
}

echo json_encode($data);