Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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
Forms Codeigniter使用复选框从表单更新mysql表数据_Forms_Codeigniter_Checkbox_Updates_Multiple Records - Fatal编程技术网

Forms Codeigniter使用复选框从表单更新mysql表数据

Forms Codeigniter使用复选框从表单更新mysql表数据,forms,codeigniter,checkbox,updates,multiple-records,Forms,Codeigniter,Checkbox,Updates,Multiple Records,对codeigniter来说是个新手,我正在尝试从用户表单中更新选中的行 My view生成一个包含MySQL数据的表单,如下所示: <?php echo form_open('masterdata/update_customers'); ?> <table> <tr> td>&nbsp;</td><td>Customer Name</td><td>postalc

对codeigniter来说是个新手,我正在尝试从用户表单中更新选中的行

My view生成一个包含MySQL数据的表单,如下所示:

<?php 
    echo form_open('masterdata/update_customers');
?>

<table>
    <tr>
        td>&nbsp;</td><td>Customer Name</td><td>postalcode</td>
    <tr>

<?php if(isset($records)) : foreach ($records as $row) : ?>
    <tr>
        <td>
            <input type=checkbox name="editcustomer[]" id="editcustomer[]" value="<?php echo $row->id ?>">
        </td>
        <td>
            <input type="text" name="customername_<?php echo $row->id ?>" id="customername_<?php echo $row->id ?>" value="<?php echo $row->customer_name ; ?>" >
        </td>
        <td>
            <input type="text" name="postalcode_<?php echo $row->id ?>" id="postalcode_<?php echo $row->id ?>" value="<?php echo $row->postalcode ; ?>" >
        </td>
    </tr>
<?php endforeach ; ?>
    </table>
<input type="submit" value="Update Selected">
<?php else : ?>
<h2> No Records Found</h2>
<?php endif; ?>
<?php echo form_close(); ?>
我的模型功能,
update\u customer\u records
是:

function update_customer_records($data)
{

        $this->db->where('id',$this->input->post('id'));
    $this->db->update('customers',$data);


}
我知道这里缺少了很多内容,比如只处理选中的行。但不确定如何添加此项。第二,根据我的视图,正在生成我的唯一名称和id是:
name=“customername”id=“customername”

如何将更新应用于唯一的表单输入名称?我需要将前缀customername和postalcode附加到输入->post(?)值


如蒙指导或协助,不胜感激。提前感谢您。

使用CodeIgniter,如果您必须获取复选框值,则必须使用$this->input->post('name\u of\u your\u checkbox')。它返回一个数组

例如,如果您在视图中有:

<input type="checkbox" name="editcustomer[]" value="1" />
<input type="checkbox" name="editcustomer[]" value="2" />
<input type="checkbox" name="editcustomer[]" value="3" />
返回:

Array {
    [0] => 1
    [1] => 2
    [2] => 3
}
public function update_customers() {

    $editcustomer = $this->input->post('editcustomer');

}
Array {
    [0] => 1
    [1] => 2
    [2] => 3
}