I have a site develop in codeigniter and I want to make a function that edit a table but I have two pages that update the table with different field.
This is my function in the model:
public function editHotel($service_id) {
$hotel_id = $this->getHotelByServiceId($service_id);
$hotel = array(
'rating_id'=>$this->input->post('rating'),
'treatment_id'=>$this->input->post('treatment'),
'nation_id'=>$this->input->post('nation'),
'region_id'=>$this->input->post('region'),
'city_id'=>$this->input->post('city'),
'area_id'=>$this->input->post('area'),
'address'=>$this->input->post('address'),
'phone'=>$this->input->post('phone'),
'fax'=>$this->input->post('fax'),
'email'=>$this->input->post('email'),
'site'=>$this->input->post('site'),
'description_it'=>$this->input->post('description_it'),
'description_en'=>$this->input->post('description_en'),
'latitudine_google'=>$this->input->post('latitudine_google'),
'longitudine_google'=>$this->input->post('longitudine_google'),
'modified'=> date('Y-m-d H:i:s'),
);
$this->db->where('service_id', $service_id);
$this->db->update('hotel',$hotel);
}
In this function I have upadtae all my table but I have a page with only some value and I want to update only this like this:
public function editDescriptionHotel($service_id) {
$hotel_id = $this->getHotelByServiceId($service_id);
$hotel = array(
'description_it'=>$this->input->post('description_it'),
'description_en'=>$this->input->post('description_en'),
'modified'=> date('Y-m-d H:i:s'),
);
$this->db->where('service_id', $service_id);
$this->db->update('hotel',$hotel);
}
And I have other page that update some value of the table.
If I use the function”editHotel” in all page the if I haven’t a input codeigniter insert 0 into the field of the table
Is possible to use only the first function “editHotel” and update only the fields that I post?
I want to use only a function in all pages that update not all fields but only the fields that I have in the page. Is possible?
I don’t want to every page that update the table to write a different function update of the table
Well, if you make it so that your input fields have the same name as your table columns, that’s easy:
For a finer control, and a better reusability, you can pass as argument an array of escludable indexes (those who won’t or you don’t want to match your column names).
And you can go even further, and make a list of extra fields you want added: