I have a form for a hotel site, where I want to update its services, and the client wants to update multiple services at a time. However I'm lost as how to save it in the database with the model.
I already built my controller, it looks something like this:
$items = array(
array(
'id' => $this->input->post('id1', true),
'hotel_id' => $hotel_id,
'des_servicio' => $this->input->post('des_servicio1', true),
'est_activo' => $this->input->post('est_activo1', true)
),
array(
'id' => $this->input->post('id2', true),
'hotel_id' => $hotel_id,
'des_servicio' => $this->input->post('des_servicio2', true),
'est_activo' => $this->input->post('est_activo2', true)
),
array(
'id' => $this->input->post('id3', true),
'hotel_id' => $hotel_id,
'des_servicio' => $this->input->post('des_servicio3', true),
'est_activo' => $this->input->post('est_activo3', true)
)
);
$this->hotel_model->save_multiple($items);
[UPDATE]
this is how my new model looks like:
function save_multiple($items = array())
{
$this->db->insert_batch($this->__tabla, $items);
return $this->db->affected_rows();
}
My issue is that now it creates 10 rows (my original form has 10 fields) even if I only populate 3 fields. So in my database 3 services get stored, and also 7 blank rows. How can change this?