插入批量数据数组? [英] insert batch data array?
问题描述
我想插入继 insert_batch
数据在数据库表下面的例子(MySQL的):
I want insert following data by insert_batch
as in following example in database table (mysql):
HTML
<input name="u_id[0][0]" value="76">
<input name="un[0][0]" value="1">
<input type="text" name="ue[0][0]" value="11">
<input type="text" name="up[0][0]" value="111">
<input name="u_id[1][0]" value="77">
<input name="un[1][1]" value="2">
<input type="text" name="ue[1][1]" value="22">
<input type="text" name="up[1][1]" value="222">
<input name="un[1][2]" value="3">
<input type="text" name="ue[1][2]" value="33">
<input type="text" name="up[1][2]" value="333">
PHP:
$u_id = $this->input->post('u_id');
$un = $this->input->post('un');
$up = $this->input->post('up');
$ue = $this->input->post('ue');
$data = array();
foreach ($un as $idx => $name) {
$data[] = array(
'u_id' => $u_id[$idx],
'un' => $un[$idx],
'up' => $up[$idx],
'ue' => $ue[$idx],
);
};
$this -> db -> insert_batch('units', $data);
我想插入他们的心情:
I want insert they as this:
如何应该改变的PHP code和HTML code?我该怎么办?
How should change php code and html code? what do i do?
推荐答案
我假设你正在使用codeIgniter并以被称为要插入数据库表的名称'单位',其' ID列是自动增量。
I am assuming you are using CodeIgniter and that the name of the database table that you want to insert to is called 'units' and that its 'id' column is autoincrement.
我立足了使用我的电话从codeIgniter用户指南版本2.0.3解决了帮手($这个 - &GT; DB-GT&; insert_string())
数据库类的。
I am basing off my solution from CodeIgniter User Guide Version 2.0.3 using a call to a helper ($this->db->insert_string())
of the Database class.
foreach ($data as $row)
{
$error_code = $this->db->insert_string('units', $row);
}
请参阅 HTTP://$c$cigniter.com/user_guide/database/ helpers.html
这Database类提供了 insert_string
功能似乎需要一个关联数组,搭建起一个插入
语句元素中,执行它,然后返回一个数字错误code。
The insert_string
function that the Database class provides appears to take an associative array, build an INSERT
statement from the elements inside, execute it and then return a numerical error code.
这篇关于插入批量数据数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!