【发布时间】:2018-06-17 09:31:52
【问题描述】:
如何从该数组中提取字段:chat_id?我正在尝试将 chat_id 放在 html 中按钮的 id 中。
Array
(
[0] => stdClass Object
(
[id] => 2
[first_name] => Armani
[last_name] => Dee
[contact_number] => 123456
[email_address] => hello@gmail.com
[home_address] =>
[username] => armani
[password] => 12345
[status] => 0
[email_confirmed] => 0
[chat_id] => 14
[admin_id] => 0
[customer_id] => 2
[partner_id] => 0
[timestamp] => 2018-06-15 22:38:24
[chat_exists] => 1
[reply_id] => 208
[message] => Hello
[timestamp_reply] => 2018-06-16 14:02:44
[chat_status] => 0
)
)
我从我的模型中得到了输出:
public function chat_customer($enum)
{
$this->db->select('*');
$this->db->from('customer');
$this->db->order_by('timestamp','desc');
$this->db->where('customer.id',$enum);
$this->db->join('chat','chat.customer_id = customer.id','left');
$this->db->join('chat_reply', 'chat_reply.chat_id = chat.chat_id', 'left');
$query = $this->db->get();
return $query->result();
}
然后我像这样在我的控制器中检索它:
$customer_id = $this->input->get('message');
$this->load->model('Crud_model');
$data = $this->Crud_model->chat_customer($customer_id);
echo print_r($data);
我正在尝试在 chat_id 上打印 14。 感谢您的帮助!
【问题讨论】:
-
$var[0]->chat_id -
@Metalik 您好,感谢您回答我的问题,但我已经尝试过了,但出现了一个错误,指出未定义的偏移量 0。
-
@pradeep 你好!我尝试了这些但仍然没有运气: echo $data['0']['chat_id'];回声 $data['chat_id']; echo $data->chat_id;
-
试试这个
echo $data[0]->chat_id; -
@pradeep 非常感谢,但我仍然收到一个错误,指出未定义的偏移量 0。
标签: php codeigniter codeigniter-3