CodeIgniter更新数据库MULTIDIMENSIONAL数据行与复选框

时间:2014-05-20 02:45:14

标签: php jquery html mysql codeigniter

我很困惑。我已经分析了几个小时..
我想要的是: “带有所选复选框的每个表格行将使用输入的值进行更新。”

任何人都可以提供帮助? 谢谢,

利奥

admin.php的

function submit_acc(){
        $this->access_chk(); //CHECK USER ACCESS
        $this->form_validation->set_error_delimiters(' ', '<br />');
         $checkbox=$this->input->post('cek');
        $sbm=$this->input->post('sbm');
        if($sbm == "Update" && $checkbox!=false){
            foreach ($checkbox as $row_id) {
             // echo($this->input->post('bank_accname'));
                $this->form_validation->set_rules("type", "bank name", "required");
                $this->form_validation->set_rules("isactive", "Status Bank", "required");

            if(!$this->form_validation->run()){ exit(validation_errors()); }
echo "update x where y =$row_id";
echo $_POST["accgroup"].$_POST["type"].$this->input->post('bank_accname').$_POST["bank_accnumber"].$_POST["isactive"];

$data[] = array (
        "acc_id"                =>  $row_id,
        "acc_accgroup_id"       =>  $_POST["accgroup"],
        "acc_bank_name"         =>  $_POST["type"],
        "acc_bank_accname"      =>  $this->input->post('bank_accname'),
        "acc_bank_accnumber"    =>  $_POST["bank_accnumber"],
        "acc_isactive"          =>  $_POST["isactive"]
    );
              $uid=$row_id;
            //      echo $uid;
            }

            //var_dump($data);
            //var_dump($checkbox);
$this->db->update_batch('acc', $data, 'acc_id');
exit("end");

View.php

<form action="<?php echo site_url("admin/submit_acc"); ?>" method="post" id="form">
<table>
        <tr >
            <td align="center"><?php echo $i; ?></td>
            <input type="hidden" name="id[]" value="<?php if(isset($r)) echo $r["acc_id"]; ?>" />
            <input type="hidden" name="isactive[]" value="<?php if(isset($r)) echo $r["acc_isactive"]; ?>" />
            <td><input type="text" class="textbox" style="width:200px;" value="<?php if(isset($r)) echo $r["acc_bank_name"]; ?>" name="type[]"  id="type" /></td>
            <td><input type="text" class="textbox" style="width:200px;" value="<?php if(isset($r)) echo $r["acc_bank_accname"]; ?>" name="bank_accname[]" id="bank_accname"  /></td>
            <td><input type="text" class="textbox" style="width:200px;" value="<?php if(isset($r)) echo $r["acc_bank_accnumber"]; ?>" name="bank_accnumber[]"  id="bank_accnumber" /></td>


<!--<input type='radio' name="isactive_<?php echo $r['acc_id'];?>" value=1 
            <?php if ($r["acc_isactive"]=='1') echo 'checked'; ?>  > -->

&nbsp;G&nbsp;       
        <select name="accgroup[]">
        <option value='<?php echo $r["accgroup_no"]; ?>' id="account_id"><?php echo $r['accgroup_no']; ?></option>
        <?php echo $stropt; ?></select>
<!-- <input type='radio' name='isactive_<?php echo $r['acc_id'];?>' value=0 <?php if ($r["acc_isactive"]=='0')echo 'checked'; ?>> Off&nbsp; -->

“&gt;                                                                 

            </table>
   </form>

我的尝试和它不工作:如果我不选择第一行,第二行不会更新。关键是我的复选框应该检查所有功能正常。如果没有,它将根据选中的复选框的数量开始更新行。有人可以告诉我,我错过了什么?????

    $data=array();          

    $data['checkbox']=$this->input->post('cek');
    $data['id']=$this->input->post('id',true);
    $data['accgroup']=$this->input->post('accgroup',true);
    $data['type']=$this->input->post('type',true);
    $data['bank_accname']=$this->input->post('bank_accname',true);
    $data['bank_accnumber']=$this->input->post('bank_accnumber',true);
    $data['isactive']=$this->input->post('isactive',true);

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

        if($sbm == "Update" && $data['checkbox']!=false){



    foreach ($data['checkbox'] as $key => $each) {

             // echo($this->input->post('bank_accname'));
             echo $data["accgroup"][$key];
                $this->form_validation->set_rules("type", "bank name", "required");
                $this->form_validation->set_rules("isactive", "Status Bank", "required");

            if(!$this->form_validation->run()){ exit(validation_errors()); }

              $temp[] = array (
        "acc_id"                =>  $data["id"][$key]   ,
        "acc_accgroup_id"       =>  $data["accgroup"][$key],
        "acc_bank_name"         =>  $data["type"][$key],
        "acc_bank_accname"      =>  $data['bank_accname'][$key],
        "acc_bank_accnumber"    =>  $data["bank_accnumber"][$key],
        "acc_isactive"          =>  $data["isactive"][$key]
    );
              $uid=$key;
            //      echo $uid;
            }

            var_dump($temp);
            //var_dump($checkbox);
$this->db->update_batch('acc', $temp, 'acc_id');
exit("end");

0 个答案:

没有答案