亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

試圖獲取非對象的屬性“join_id”

試圖獲取非對象的屬性“join_id”

PHP
冉冉說 2023-03-04 18:13:22
請告訴我如何解決這個問題,我從我的 PHP CodeIgniter API 得到錯誤錯誤嘗試獲取非對象的屬性“join_id”詢問Select * from join_chat where(user_1 = '24' and user_2 = '26') or(user_1 = '26' and user_2 = '24')result of query+---------+--------+--------+| join_id | user_1 | user_2 |+---------+--------+--------+|      20 | 26     | 24     |+---------+--------+--------+1 row in set (0.01 sec)從結果中,您可以看到連接 ID 返回為 20,但我收到錯誤Trying to get property 'join_id' of non-object請參閱下面的控制器方法 public function get_join_user()    {        $this->load->library('form_validation');        $this->form_validation->set_rules('post_user_id', 'post_user_id', 'trim|required');        $this->form_validation->set_rules('login_user_id', 'login_user_id', 'trim|required');        if ($this->form_validation->run() == false) {            $data["responce"] = false;            $data["error"] = 'field is required';        } else {            $this->load->model("common_model");            $q = $this->db->query("Select * from join_chat where                      (user_1 = '".$this->input->post("login_user_id")."' and user_2 = '".$this->input->post("post_user_id")."') or                      (user_1 = '".$this->input->post("post_user_id")."' and user_2 = '".$this->input->post("login_user_id")."')");            //$row = $q->row();            $row = $q->result();            if (count($row) > 0) {                $data["responce"] = true;                //*****error causing line below***                $data["data"] = $row->join_id;            } 導致錯誤的行$data["data"] = $row->join_id;
查看完整描述

1 回答

?
慕容3067478

TA貢獻1773條經驗 獲得超3個贊

再次@Mlike Eps,現在您已經將代碼從更改$q->row();$row = $q->result();引用:prev_question。現在它是一個對象數組,因此您必須相應地獲取數據。

$data["data"]?=?$row[0]->join_id;?//because,?now?array[0]?contains?the?previous?information.

如果萬一它有多個數組,請使用它foreach()來檢索數據。希望對你有幫助。:)


查看完整回答
反對 回復 2023-03-04
  • 1 回答
  • 0 關注
  • 137 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號