0

I have an array, that needs to be inserted into DB (every value is new row). Do I have to do coding like this, or there are other way to do this?

function galerija_insert($name){
foreach($name as $nm) :
$data['name'] = $nm;
$this->db->insert('galerija', $data);
endforeach;
}

1 Answer 1

2

If you want to minimize the number for insert queries, you can use insert_batch like this:

$rows = array();
foreach($name as $nm) {
    $rows[] = array('name' => $nm);
}
$this->db->insert_batch('galerija', $rows);
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.