php - codeigniter:如何将数组的值放入特定的表列中?

标签 php mysql sql codeigniter insert

我有一个这样的数组

array(12) {
            [0]=> string(1) "3"
            [1]=> string(1) "3"
            [2]=> string(1) "5"
            [3]=> string(1) "3"
            [4]=> string(1) "4"
            [5]=> string(1) "3"
            [6]=> string(1) "3"
            [7]=> string(1) "3"
            [8]=> string(1) "2"
            [9]=> string(1) "3"
            [10]=> string(1) "2"
            [11]=> string(1) "3" 
        } 

数组是动态的,所以数组的值可以随时改变

我也有一个mysql表,结构是这样的

|id|bobot_c1|bobot_c2|bobot_c3|bobot_c4|bobot_c5|bobot_c6|bobot_c7|bobot_c8|bobot_c9|bobot_c10|bobot_c11|bobot_c12|
-------------------------------------------------------------------------------------------------------------------
|  |        |        |        |        |        |        |        |        |        |         |         |         | 
-------------------------------------------------------------------------------------------------------------------

idauto_increment

如何将键数组:"3"、"3"、"5"、"3" 等输入到数据库表中?

所以对于值 index [0],我进入 bobot_c1 列,index [1],进入 bobot_c2 专栏等。

谢谢!

最佳答案

像这样创建另一个数组:

$dataArray = (
       'bobot_c1' => $array[0],
       'bobot_c2' => $array[1],
       'bobot_c3' => $array[2],
       'bobot_c4' => $array[3],
        .
        .
        .
       );

类似地添加更多列并将 $dataArray 插入数据库。

关于php - codeigniter:如何将数组的值放入特定的表列中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30409731/

相关文章:

php - 在 Laravel 中提交表单后如何重定向到另一个页面

php - 使用Mysql和php对多列求和

sql - 统计每分钟插入的记录数

mysql - Mysql数据库中非varchar列的加密和解密

mysql - 如何使用 MySQL 按特定顺序对行进行排序?

SQL INNER JOINing 2 个子查询

mysql - 在 'count' 子句中包含多个表的 MySQL 查询中添加 'from'

php - 如何使我的 SQL 查询按以关键字开头的名称排序?

php - 从 php 回显 html 代码到 html

mysql - Excel,通过将唯一值移动到另一个工作表来删除重复项