Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Foreach数组更新数据库表时使用数组中的这些元素_Php_Arrays - Fatal编程技术网

Php Foreach数组更新数据库表时使用数组中的这些元素

Php Foreach数组更新数据库表时使用数组中的这些元素,php,arrays,Php,Arrays,如何在php中获取数组元素的第一个值。 我的故事板是这样的: ( [0] => Array ( [ID] => 68 [MATERIAL] => I have [AC] => Try ) [1] => Array ( [ID] => 69 [MATERIAL] => It [AC] => No Surrender )

如何在php中获取数组元素的第一个值。 我的故事板是这样的:

(
[0] => Array
    (
        [ID] => 68
        [MATERIAL] => I have
        [AC] => Try
    )

[1] => Array
    (
        [ID] => 69
        [MATERIAL] => It 
        [AC] => No Surrender
    )
我有这样一个数组:

(
[0] => Array
    (
        [ID] => 68
        [MATERIAL] => I have
        [AC] => Try
    )

[1] => Array
    (
        [ID] => 69
        [MATERIAL] => It 
        [AC] => No Surrender
    )
)

我想像这样更新数据库中的一些记录

对于数组的每个元素

更新我的选项卡集MATERIAL=[MATERIAL],AC=[AC],其中id=[id]

这是名为m_admin的模型:

public function update_eir_to_cost($id, $material, $ac) {
    $data = array(
        "MATERIAL" => $material,
        "AC" => $ac);
    $this->db->trans_start();
    $this->db->where($id);
    $this->db->update('tb_repair_detail', $data);
    $this->db->trans_complete();

    if ($this->db->trans_status() === FALSE) {
        // generate an error... or use the log_message() function to log your error
        echo "Error Updating";
    } else {
        echo "Alhamdulillah";
    }
}
这是控制器:

public function update_json_detail() {
    $post_data = $this->input->post("POST_ARRAY");
    $execute = array();
    foreach ($post_data as $data) {
        $execute[] = array(
            'ID'=> $data['0'],
            'MATERIAL' => $data['7'],
            'AC' => $data['8']
        );
    }


    echo "<pre>";
    print_r($execute); // return an array like above.

    /*forech element
        update table using model
    */

}
public function update\u json\u detail(){
$post_data=$this->input->post(“post_数组”);
$execute=array();
foreach($post_数据作为$data){
$execute[]=数组(
'ID'=>$data['0'],
'MATERIAL'=>$data['7'],
'AC'=>$data['8']
);
}
回声“;
print_r($execute);//返回如上所示的数组。
/*止推元件
使用模型更新表
*/
}

这将解决您的问题:

public function update\u json\u detail(){
$post_data=$this->input->post(“post_数组”);
$execute=array();
foreach($post_数据作为$data){
$execute[]=数组(
'ID'=>$data['0'],
'MATERIAL'=>$data['7'],
'AC'=>$data['8']
);
}
回声“;
print_r($execute);//返回如上所示的数组。
$this->load->model('m_admin');
foreach($row执行){
$this->m_admin->update_eir_to_cost($row['ID'],$row['MATERIAL'],$row['AC']);
}
}

您使用的是什么框架?代码点火器?