Php 如何使用codeigniter将多个数组插入数据库
我已经发布了$a、$b、$c……的值,它们是数组格式的 我给这个的模型文件Php 如何使用codeigniter将多个数组插入数据库,php,arrays,codeigniter,Php,Arrays,Codeigniter,我已经发布了$a、$b、$c……的值,它们是数组格式的 我给这个的模型文件 function insert_bank_data($da,$b,$c,$d,$e) { $data=array('date'=>$da,'des'=>$b,'amount'=>$c,'price'=>$d); $this->db->insert_batch('total_trans',$data); } 我犯了这样的错误 You ha
function insert_bank_data($da,$b,$c,$d,$e)
{
$data=array('date'=>$da,'des'=>$b,'amount'=>$c,'price'=>$d);
$this->db->insert_batch('total_trans',$data);
}
我犯了这样的错误
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22' at line 1
如果函数的参数是相同长度的数组,则应编写
function insert_bank_data($da,$b,$c,$d,$e)
{
$data = array();
for ($i-0; $i < count($da); $i++) {
$data[] = array('date'=>$da[$i],'des'=>$b[$i],'amount'=>$c[$i],'price'=>$d[$i]);
$this->db->insert_batch('total_trans',$data);
}
函数插入银行数据($da、$b、$c、$d、$e)
{
$data=array();
对于($i-0;$i$da[$i],'des'=>b[$i],'amount'=>c[$i],'price'=>d[$i]);
$this->db->insert_batch('total_trans',$data);
}
您可以使用json_encode()
你也可以用这个
function insert_bank_data($da,$b,$c,$d,$e)
{
for ($i=0; $i < count($da); $i++) {
$data= array('date'=>$da[$i],'des'=>$b[$i],'amount'=>$c[$i],'price'=>$d[$i]);
$this->db->insert('total_trans',$data);
}
}
函数插入银行数据($da、$b、$c、$d、$e)
{
对于($i=0;$ida[$i],'des'=>b[$i],'amount'=>c[$i],'price'=>d[$i]);
$this->db->insert('total_trans',$data);
}
}
为什么要使用;
两次?我删除了它。仍然是新台币的$da、$b、$c、$d、$e数组?是的。这些都是数组。当我打印时,…我得到了'2015年12月30日'、'2015年12月30日'、'2015年12月29日'、'2015年12月28日'。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
function insert_bank_data($da,$b,$c,$d,$e)
{
for ($i=0; $i < count($da); $i++) {
$data= array('date'=>$da[$i],'des'=>$b[$i],'amount'=>$c[$i],'price'=>$d[$i]);
$this->db->insert('total_trans',$data);
}
}