Reputation: 1
This is in my model.. it says Object of class CI_DB_mysql_result could not be converted to int.. the problem is in the select_max('id'); and it always result to 1. Please help i'm new to 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";
}
}
Upvotes: 0
Views: 50
Reputation: 12117
You have not get max ID
in result, please try this way
change
$this->db->select_max('id');
$result = $this->db->get('establishment');
to
$this->db->select_max('id');
$result = $this->db->get('establishment')->row()->id;
Upvotes: 1