UPDATE从数组值查询

时间:2013-02-18 21:28:52

标签: php codeigniter

我想通过codeigniter上的数组数据更新数据库表中的值,但我输出错误。怎么解决它?

PHP:

$mainpage = $this - > input - > post('mainpage');
$data2 = array();
foreach($mainpage as $idx = > $name) {
    $data2[] = array(
        'mainpage' = > $name[0],
        'subpage' = > json_encode($this - > input - > post('subpage')[$idx]),
        'service' = > json_encode($this - > input - > post('tdadeps')[$idx]),
        'id_relation' = > $id_relation, );
    $this - > db - > where('id_relation', $id_relation);
    $data22 = $this - > db - > update('access_level', $data2);
}

输出错误:

A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: mysql/mysql_driver.php
Line Number: 612

A Database Error Occurred
Error Number: 1054
Unknown column '0' in 'field list'
UPDATE `access_level` SET `0` = Array WHERE `id_relation` = '2'
Filename: W:\system\database\DB_driver.php
Line Number: 330

1 个答案:

答案 0 :(得分:0)

我希望看到更多代码,但请尝试以下代码:

$mainpage = $this - > input - > post('mainpage');
$data2 = array();
foreach($mainpage as $idx = > $name) {
    $data2 = array(
        'mainpage' = > $name[0],
        'subpage' = > json_encode($this - > input - > post('subpage')[$idx]),
        'service' = > json_encode($this - > input - > post('tdadeps')[$idx]),
        'id_relation' = > $id_relation);
    $this - > db - > where('id_relation', $id_relation);
    $data22 = $this - > db - > update('access_level', $data2);
}

让我知道是否有效