Ich habe eine CodeIgniter Anwendung und eine MySQL-Tabelle mit der folgenden Struktur:CodeIgniter Batch einfügen in bestimmten Spalten
Table shortlisted_candidates
id int PRIMARY KEY AUTO INCREMENT,
candidate_no int NOT NULL,
written_marks int,
viva_marks int
Ich möchte insert_batch
in dieser Tabelle zu tun, aber Daten werden nur in id
und candidate_no
Spalten eingefügt werden .
Ich weiß Codeigniter Active Records Class bietet die $this->db->insert_batch()
Funktion für Batch einfügen, aber es fügt tatsächlich Daten in der gesamten Tabelle, während ich möchte, dass Daten nur in bestimmten Spalten eingefügt werden. Wie kann ich dies in CodeIgniter erreichen?
Beachten Sie, dass id
eine AUTO INCREMENT, PRIMARY KEY-Spalte ist.
Mein 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?
}
}
Also, was ist der Fehler oder das Problem? – Abhinav
Also wo sind '$ Daten' Werte? –
@ IdentityUnkn0wn es fügt nur eine Zeile ein, und '$ data ['candidate_no']' = 0. –