I have a CodeIgniter application and a MySQL table with the following structure:
Table shortlisted_candidates
id int PRIMARY KEY AUTO INCREMENT,
candidate_no int NOT NULL,
written_marks int,
viva_marks int
I want to do insert_batch into this table, but data will only be inserted in id and candidate_no columns.
I know Codeigniter Active Records Class provides the $this->db->insert_batch() function for batch insert but it actually inserts data in the entire table, whereas I want data to be inserted only into specific columns. How can I achieve this in CodeIgniter?
Note that id is an AUTO INCREMENT, PRIMARY KEY column.
My Controller code:
class Shortlisted_candidates extends MY_Controller
{
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->model('Shortlisted_candidate');
$this->load->helper('url');
$this->load->helper('html');
$this->load->helper('form');
$this->output->enable_profiler(false);
}
function add(){
$data = array();
if ($_POST) {
$data['candidate_no'] = $this->input->post('candidate_no');
$this->Shortlisted_candidate->add_candidate_to_shortlist($data);
$this->session->set_flashdata('message', 'Data Successfully Added');
redirect('shortlisted_candidates/add');
}
}
}
My Model code:
class Shortlisted_candidate extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function add_candidate_to_shortlist($data){
//Following code inserts data in ALL COLUMNS
$this->db->insert_batch('shortlisted_candidates', $data);
//How to write active record batch insert query for inserting data in only `id` and `candidate_no` column?
}
}
$datavalues??$data['candidate_no']= 0.