Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9316823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:43:17+00:00 2026-06-19T02:43:17+00:00

I have a site develop in codeigniter and I want to make a function

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:43:18+00:00Added an answer on June 19, 2026 at 2:43 am

    Well, if you make it so that your input fields have the same name as your table columns, that’s easy:

    public function updateHotels($service_id) 
    {
       $hotel_id = $this->getHotelByServiceId($service_id);
       $fields = array();
    
       foreach($this->input->post() as $k => $v){
        if($k != 'submit'){   //or anything you always want to esclude
          $fields[$k] = $v;
        }
       }
    
       $fields['modified'] = date('Y-m-d H:i:s');
    
       $this->db->where('service_id', $service_id);
       $this->db->update('hotel', $fields);
    }
    

    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:

    $exclude = array('submit', 'other_field');
    $extra = array('modified' => date('Y-m-d H:i:s'));
    
    public function updateHotels($service_id, $exclude, $extra) 
        {
           $hotel_id = $this->getHotelByServiceId($service_id);
           $fields = array();
    
           foreach($this->input->post() as $k => $v){
            if(!in_array($k, $exclude){
              $fields[$k] = $v;
            }
           }
    
           $columns = array_merge($fields, $extra);
    
           $this->db->where('service_id', $service_id);
           $this->db->update('hotel', $columns);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a site develop in cakephp 2.0 I want to make a HABTM
I have a site develop in jquery. I want to select all id that
I have a site develop in codeigniter. I want to validate a form and
I'm trying to develop a site using Zend Framework, but i have a problem:
We have to develop an Ecommerce site with 20+ pages of static content which
We will develop a web site that will have some free services and we
I have a problem in a site that I am trying to develop Sometimes
I have site which uses $(selector).load(path) function in more than 300 pages. Now my
I have a site develop in Codeigniter, and in my model I have a
I have a site develop in cakephp 2.0. I have a table Product related

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.