請告訴我如何解決這個問題,我從我的 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條經(jīng)驗 獲得超3個贊
再次@Mlike Eps,現(xiàn)在您已經(jīng)將代碼從更改$q->row();
為$row = $q->result();
引用:prev_question?,F(xiàn)在它是一個對象數(shù)組,因此您必須相應地獲取數(shù)據(jù)。
$data["data"]?=?$row[0]->join_id;?//because,?now?array[0]?contains?the?previous?information.
如果萬一它有多個數(shù)組,請使用它foreach()
來檢索數(shù)據(jù)。希望對你有幫助。:)
- 1 回答
- 0 關注
- 135 瀏覽
添加回答
舉報
0/150
提交
取消