我在我的网站上使用codeigniter,但是我有一个问题我已经完成了从不同表中返回行的脚本。但它写了我错误试图获取非对象的属性。这是我的代码。哪里有问题?
$this->db->select('*');
$this->db->from('orders');
$this->db->where('order_id',$order_id);
$array_keys_values = $this->db->get();
$row = $array_keys_values->row();
$this->db->select('*');
$this->db->from('pacients');
$this->db->where('pacient_account_id',$row->order_pacient_id);
$array_keys_values2 = $this->db->get();
$row2 = $array_keys_values2->row();
$this->db->select('*');
$this->db->from('doctors');
$this->db->where('doctor_account_id',$doctor_id);
$array_keys_values3 = $this->db->get();
$row3 = $array_keys_values3->row();
答案 0 :(得分:2)
尝试
$this->db->select('*');
$this->db->from('orders');
$this->db->where('order_id',$order_id);
$array_keys_values = $this->db->get();
if ($array_keys_values->num_rows() > 0) {
foreach ($array_keys_values->result() as $row) {
// now you can work with $row
}
}
$this->db->select('*');
$this->db->from('pacients');
$this->db->where('pacient_account_id',$row->order_pacient_id);
$array_keys_values2 = $this->db->get();
if ($array_keys_values2->num_rows() > 0) {
foreach ($array_keys_values2->result() as $row2) {
// now you can work with $row2
}
}
$this->db->select('*');
$this->db->from('doctors');
$this->db->where('doctor_account_id',$doctor_id);
$array_keys_values3 = $this->db->get();
if ($array_keys_values3->num_rows() > 0) {
foreach ($array_keys_values3->result() as $row3) {
// now you can work with $row3
}
}
答案 1 :(得分:0)
没有返回任何行。使用带有num_rows()>的if语句0来检查