CodeIgniter Forums
Getting POST data in loop - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Getting POST data in loop (/showthread.php?tid=76643)



Getting POST data in loop - fci_alex - 06-05-2020

Sorry for my English Cool
I update the database table from the model, getting the id of the current record and field values through the controller.
Everything is working fine:
Code:
function update_record(){
           
           
            if (isset($_POST['id'])){
        $id=$this->input->post('id');
                $this->db->set('id', $id);
            }
           
            if (isset($_POST['date_doc'])){
                $date_doc=$this->input->post('date_doc');
                $this->db->set('date_doc', $date_doc);
            }
           
            if (isset($_POST['num_batch'])){
                $num_batch=$this->input->post('num_batch');
                $this->db->set('num_batch', $num_batch);
            }
                    
         $this->db->where('id', $id);   
         $result=$this->db->update('doc_prod_request');
               
         return $result;
    }

I want to get the form fields (their names = the names of the table fields) and their values in the loop.
Something like this:

Code:
$fields = $this->db->list_fields('doc_prod_request');
                foreach ($fields as $field)
                {
                    if (isset($_POST[$field])){                    
                        $field=$this->input->post($field);
                        $this->db->set($field, $field);
                    }
                }

But naturally, such a construction does not allow writing the assignment of values to variables:
Code:
$this->db->set($field, $field);

They are overwritten.
Tell me how this can be implemented.

Thanks in advance.