插入批量数据数组?

编程入门 行业动态 更新时间:2024-10-14 08:24:26
本文介绍了插入批量数据数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想插入继 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/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.

更多推荐

插入批量数据数组?

本文发布于:2023-10-27 10:35:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533114.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   批量   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!