0

我为我的网站使用 codeigniter,但我有一个问题,我已经完成了从不同表返回行的脚本。但它给我写了错误Trying to get property of non-object。这是我的代码。哪里有问题?

      $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();
4

2 回答 2

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
    }
}
于 2012-10-28T16:55:56.897 回答
0

没有返回任何行。使用 num_rows() > 0 的 if 语句进行检查

于 2012-10-29T14:31:37.147 回答