CodeIgniter Forums

Full Version: [SOLVED]Update multiple form
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]redraw[/eluser]
Hello All,

I have problem with multiple update

here my view :
Code:
<form name="form1" id="form1" method="post" action="">
<?php $i = 0; ?>
<?php foreach($detail->result() as $rows):?>

    <input type="hidden" name="<?php echo 'trans['.$i.'][master_id]'; ?>" value="<?php echo $rows->master_id; ?>">
    <input type="hidden" name="<?php echo 'trans['.$i.'][user]'; ?>" value="<?php echo $rows->user; ?>">
    <input type="hidden" name="<?php echo 'trans['.$i.'][no_bukti]'; ?>" value="<?php echo $rows->no_bukti; ?>">
    <input type="hidden" name='<?php echo 'trans['.$i.'][jenis]'; ?>' id='jenis' value="<?php echo $rows->jenis; ?>" class='trans[][jenis]'>


    <select name="&lt;?php echo 'trans['.$i.'][code]'; ?&gt;" id="&lt;?php echo 'trans['.$i.'][code]'; ?&gt;"style='width:35%'>
        &lt;?php
            echo "<option value=".$rows->code.">" . $rows->code ." - ". $rows->account . "</option>";
            foreach($detail_nomer->result() as $row){
                    echo "<option value=".$row->code.">" . $row->code ." - ". $row->account . "</option>";
            }
         ?&gt;
        </select>
    &lt;input type="text" name="&lt;?php echo 'trans['.$i.'][keterangan]'; ?&gt;" id="&lt;?php echo 'trans['.$i.'][keterangan]'; ?&gt;" value="&lt;?php echo $rows-&gt;keterangan;?&gt;"  style='width:45%'>
    &lt;input type="text" name="&lt;?php echo 'trans['.$i.'][nilai]'; ?&gt;" id="&lt;?php echo 'trans['.$i.'][nilai]'; ?&gt;" value="&lt;?php echo $rows-&gt;nilai;?&gt;" class='trans[][nilai]'>
<br>
&lt;?php $i++; ?&gt;
&lt;?php endforeach;?&gt;

here is my controller :
Code:
function gl_edit_trans()
    {    
        
        $y = 1;
        while($y <= count($_POST['trans']))
        {
           if (array_key_exists($y, $_POST['trans']))
           {
               $master_id = $_POST['trans'][$y]['master_id'];
               $no_bukti = $_POST['trans'][$y]['no_bukti'];
               $code = $_POST['trans'][$y]['code'];
               $keterangan = $_POST['trans'][$y]['keterangan'];
               $keterangan = strtoupper($keterangan);
               $user = $_POST['trans'][$y]['user'];
               $nilai = $_POST['trans'][$y]['nilai'];
               $nilai = str_replace(',','',$nilai);
              
               print_r($_POST['trans']);
              $data = array(
                            'master_id'    => $master_id,
                          'no_bukti'    => $no_bukti,
                          'code'         => $code,
                          'keterangan'     => $keterangan,
                          'user'         => $user,
                          'nilai'         => $nilai
                          
              );
              
              $this->gl_model->edit_master_trans($data);
           }
           $y++;
        }
         $this->gl_lihat_trans();

    }

and this is my model :
Code:
function edit_master_trans($newdata = array())
{
        
    if( ! empty($newdata));
                      
    //the problem is -- > $this->db->where('master_id',$newdata);
    //the problem is -- > $this->db->where('no_bukti',$newdata);
    $this->db->update('gl_master',$newdata);
            
    }

the problem is in my model. i no idea to parsing array post of the 'master_id' and 'no_bukti' into the model.

thankyou