Mysql 如何使用CodeIgniter在数据库中插入多个值?
我尝试使用codeignitor在mysql数据库中插入多个数据值。但它不起作用 我犯了以下错误 文件名:D:/wamp/www/aal stock/system/database/DB_driver.php 电话号码:691 控制器:Mysql 如何使用CodeIgniter在数据库中插入多个值?,mysql,arrays,codeigniter,insert,Mysql,Arrays,Codeigniter,Insert,我尝试使用codeignitor在mysql数据库中插入多个数据值。但它不起作用 我犯了以下错误 文件名:D:/wamp/www/aal stock/system/database/DB_driver.php 电话号码:691 控制器: function itemsallocated() { if($this->session->userdata('Username') != '') { $this->load-
function itemsallocated()
{
if($this->session->userdata('Username') != '')
{
$this->load->model("main_model");
$pn=$this->input->post('Part_Number');
$desc=$this->input->post('Description');
$brand=$this->input->post('From');
//$pfrom=$this->input->post('From');
$idate=$this->input->post('Date');
$impcode=$this->input->post('Import_License_Number');
$invused=$this->input->post('Invoice_Used');
$invno=$this->input->post('Invoice_Number');
$decno=$this->input->post('Declaration_Number');
$billno=$this->input->post('Bill_Number');
$hscode=$this->input->post('HS_Code');
$coo=$this->input->post('COO');
$qty=$this->input->post('Quantity');
$Stock_Rem=$this->input->post('Stock_Rem');
$Stock_Rem2=$this->input->post('Stock_Rem2');
$cart=$this->input->post('cart');
$Allocated=$this->input->post('Allocated');
$euro=$this->input->post('Price_in_Euro');
$usd=$this->input->post('Price_in_USD');
$aed=$this->input->post('AED');
$jpy=$this->input->post('JPY');
$value=$this->input->post('Value');
$wpp=$this->input->post('Wt_Per_Piece');
$twt=$this->input->post('Total_Wt');
$L=$this->input->post('L');
$B=$this->input->post('B');
$H=$this->input->post('H');
$Added_By=$this->input->post('Added_By');
$Cus_Name=$this->input->post('Cus_Name');
date_default_timezone_set('Asia/Dubai');
$ddate= date('d-m-Y H:i:s');
$data=array('Part_Number'=>$pn,
'Description'=>$this->input->post('Description'),
'From'=>$brand,
'Date'=>$idate,
'Import_License_Number'=>$impcode,
'Invoice_Used'=>$invused,
'Invoice_Number'=>$invno,
'Declaration_Number'=>$decno,
'Bill_Number'=>$billno,
'HS_Code'=>$hscode,
'COO'=>$coo,
'Quantity'=>$qty,
'Stock_Rem'=>$Stock_Rem,
'Stock_Rem2'=>$Stock_Rem2,
'cart'=>$cart,
'Allocated'=>$Allocated,
'Price_in_Euro'=>$euro,
'Price_in_USD'=>$usd,
'AED'=>$aed,
'JPY'=>$jpy,
'Value'=>$value,
'Wt_Per_Piece'=>$wpp,
'Total_Wt'=>$twt,
'L'=>$L,
'B'=>$B,
'H'=>$H,
'd_t'=>$ddate,
'Added_By'=>$Added_By,
'Cus_Name'=>$Cus_Name
);
$this->db->insert_batch('allocated', $data);
要在CodeIgniter中插入多个数据值,请执行以下操作:
$data = array(
array(
'title' => 'My title' ,
'name' => 'My Name' ,
'date' => 'My date'
),
array(`enter code here`
'title' => 'Another title' ,
'name' => 'Another Name' ,
'date' => 'Another date'
)
);
$this->db->insert_batch('table_name', $data);
要在CodeIgniter中插入多个数据值,请执行以下操作:
$data = array(
array(
'title' => 'My title' ,
'name' => 'My Name' ,
'date' => 'My date'
),
array(`enter code here`
'title' => 'Another title' ,
'name' => 'Another Name' ,
'date' => 'Another date'
)
);
$this->db->insert_batch('table_name', $data);
您也可以这样使用:
foreach($_POST['data'] as $data)
{
$this->db->insert('table_name', $data);
}
您也可以这样使用:
foreach($_POST['data'] as $data)
{
$this->db->insert('table_name', $data);
}
请分享完整和准确的错误信息请分享完整和准确的错误信息请为您的答案添加一些解释,以便其他人可以从中学习-如果插入了大量数据,您应该强调此解决方案有严重的缺点请为您的答案添加一些解释,以便其他人可以从中学习-您应该强调的是,如果插入大量数据,此解决方案有严重的缺点