1

I am getting an error while inserting into my database.

Its showing column ARRAY. How to fix it? Instead of that I want to pass all dates (showing in the screenshot only dates in the date column)

I want to know in code where I did mistake. Why the array is coming like this?

PHP MODAL

$data_jobschedule = array(
            'jobschedule_id' => $jobschedule_id,
            'Activity_area_id' => $Activity_area_id,
            'Contract_id' => $this->input->post('getcontract_id'),
            'job_freq_id' => $this->input->post('getcontractbranch_freq'),
            'job_schedule_dates' => $this->input->post('getschedule'),
            //'job_schedule_frequency' => $this->input->post('getjob_schedule_frequency'),
            'created_at' =>$created_Dt
        );

 $insert_id = 0;
        if ($this->db->insert("activity_area", $data)) { //AM INSERTING ANOTHER RECORD ALSO TO DIFFERENT TABLE
            $this->db->insert('job_schedule', $data_jobschedule); //HERE IS THE TABLE I NEED TO ADD DATES AND FREQUENCY
            $insert_id = $this->db->insert_id();

        }
3
  • 2
    you are inserting an array into a column Commented Aug 26, 2019 at 23:30
  • so basically you want to store the job_schedule_dates array value as a column to your job_schedule table? but you mentioned Database table looks with Date and treatment, what is the meaning of it? Commented Aug 26, 2019 at 23:48
  • in database two columns are there Date and Frequency along with other columns like jobschedule_id, Activity_area_id, Contract_id, job_freq_id etc. so you need something like jobschedule_id, Activity_area_id, Contract_id, job_freq_id, Date, treatment, created_at ? Commented Aug 27, 2019 at 0:00

1 Answer 1

1

so your post data is an array, you need looping through it. on your php model, try change this

$data_jobschedule = array(
    'jobschedule_id' => $jobschedule_id,
    'Activity_area_id' => $Activity_area_id,
    'Contract_id' => $this->input->post('getcontract_id'),
    'job_freq_id' => $this->input->post('getcontractbranch_freq'),
    'job_schedule_dates' => $this->input->post('getschedule'),
    //'job_schedule_frequency' => $this->input->post('getjob_schedule_frequency'),
    'created_at' =>$created_Dt
);

$insert_id = 0;
if ($this->db->insert("activity_area", $data)) { //AM INSERTING ANOTHER RECORD ALSO TO DIFFERENT TABLE
    $this->db->insert('job_schedule', $data_jobschedule); //HERE IS THE TABLE I NEED TO ADD DATES AND FREQUENCY
    $insert_id = $this->db->insert_id();
}

to

$insert_id = 0;
if ($this->db->insert("activity_area", $data)) { //AM INSERTING ANOTHER RECORD ALSO TO DIFFERENT TABLE
    if (is_array($this->input->post('getschedule'))) {
        foreach($this->input->post('getschedule') as $value) {
            $this->db->insert('job_schedule', array(
                'jobschedule_id' => $jobschedule_id,
                'Activity_area_id' => $Activity_area_id,
                'Contract_id' => $this->input->post('getcontract_id'),
                'job_freq_id' => $this->input->post('getcontractbranch_freq'),
                'job_schedule_dates' => $value[0], //assume array form like your screenshot
                'job_schedule_frequency' => $value[1],
                'created_at' =>$created_Dt
            ));
        }

        $insert_id = $this->db->insert_id(); 
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.