1

i want to insert records of fifty persons to the database at one time(this can be increase).when user click the save button data should be save at the database.what is the best way to do it?

Here is my controller

function month_end_data()
    {
$data_save = array(
                    'employee_id' => $emp,
                    "annual" => $annual,
                    "casual" => $casual
);
                $id = $this->monthend_mod->savemonthenddata($data_save);
                echo json_encode(array("status" => TRUE, "id" => $id));
}

Model

class monthend_mod extends CI_Model
{
    public function savemonthenddata($data_save = array())
    {
        if ($this->db->insert_batch('pay_monthend', $data_save)) {
            return true;
        } else {
            return false;
        }
    }
}

view

<button onclick="month_end_data()" class="btn btn-danger">Save</button>
1

1 Answer 1

1

Try to send in a multidimensional array:

$data = array(
    array(
        'employee_id' => 'xx',
        //... more fields
    ),
    array(
        'employee_id' => 'yy',
        //... more fields
    ),
    array( 
        //... and so on
    ),
);

...and then send that to your savemonthenddata()-method.

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.