这是在我的模型中..它说类CI_DB_mysql_result的对象无法转换为int ..问题出在select_max('id'); 它总是导致1.请帮助我是codeigniter的新手
public function addEstablishment()
{
$capacity = $this->input->post('capacity');
$name = $this->input->post('name');
$curfew = $this->input->post('curfew');
$price = $this->input->post('price');
$gender = $this->input->post('gender');
$type = $this->input->post('type');
$this->db->select_max('id');
$result = $this->db->get('establishment');
$query = $result + 1;
$owner = $this->session->userdata('id');
$data = array(
'id' => $query,
'name' => $name ,
'capacity' => $capacity ,
'curfew' => $curfew ,
'gender' => $gender ,
'type' => $type ,
'owner' => $owner
);
if($this->db->insert('establishment', $data))
{
echo "Successfully added";
}
}
答案 0 :(得分:1)
你的结果没有max ID
,请尝试这种方式
变化
$this->db->select_max('id');
$result = $this->db->get('establishment');
到
$this->db->select_max('id');
$result = $this->db->get('establishment')->row()->id;