如果我的数据库表中没有记录,我收到错误提供的无效参数foreach()可以帮我解决这个错误。
控制器代码
$data['cc'] = $this->Profile_model->supplier_companydetails();
$this->load->view('suppliercompany', $data);
型号代码
public function supplier_companydetails() {
$this->db->select('*');
$this->db->from('supplier_otherdetails');
$this->db->where('supplierid_fk', $this->session->id);
$query = $this->db->get();
//return $query->result();
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
//add all data to session
$newdataaa = array(
'company_name' => $row->company_name,
'company_estd_date' => $row->company_estd_date,
'tin_number' => $row->tin_number,
'company_address' => $row->company_address,
'area' => $row->area,
'city' => $row->city,
'state' => $row->state,
'country' => $row->country,
);
}
$this->session->set_userdata($newdataaa);
return $query->result();
}
}
答案 0 :(得分:1)
只需修改此行
即可foreach ($query->result() as $row) {
致
foreach((array)$ query-> result()as $ row){