Welcome Guest, Not a member yet? Register   Sign In
Need help With Submitting a Dynamic Form
#1

[eluser]vincej[/eluser]
Hi - I have a CI form which is populated with values from a DB by looping through the DB values using a foreach. It works fine. However, I want to be able to amend those values and then return the new values back to the DB.

The problem is that because the form is built with a foreach only the very last row of DB values can be amended. This is because the previous rows get overwritten as the foreach loops through.

Question: what is the mechanism I need to use to update the values from the whole form ??

Here is the code as it exists at the moment:

Model:

Code:
function Updatelocation(){
$data = array( 'pickuplocation' => db_clean($_POST['pickuplocation']),
                         'Date1' => db_clean($_POST['Date1']),
      'Date2' => db_clean($_POST['Date2']),
     'Date3' => db_clean($_POST['Date3']),
    
     );

$this->db->where('pickuplocation', $_POST['pickuplocation']);
$this->db->update('pickup',$data);

}



Controller:

Code:
function UpdateLocation(){
$this->MPickup->UpdateLocation();
redirect('admin/pickup_detail','refresh');
}


View:

Code:
<?php
echo form_open('admin/pickup_detail/Updatelocation');
?>

<table width="800" border="30" cellpadding="5" align="center"  >
  <tr>
   &lt;!-- <th scope="col">Pick Up ID</th>--&gt;
    <th width="147" scope="col">Pick Up Location</th>
    <th width="98" scope="col">Date 1 </th>
    <th width="98" scope="col">Date 2 </th>
    <th width="98" scope="col">Date 3</th>

&lt;?php
foreach ($query->result_array() as $row) {
?&gt;
<tr align="center">
    <td>&lt;?php $data = array('name'=>'pickuplocation','id'=>$row['pickupid'],'size'=>20,'value' => $row['pickuplocation']); echo form_input($data); ?&gt;</td>
    <td>&lt;?php $data = array('name'=>'Date1','id'=>$row['Date1'],'size'=>20,'value' =>$row['Date1']); echo form_input($data); ?&gt;</td>
    <td>&lt;?php $data = array('name'=>'Date2','id'=>$row['Date2'],'size'=>20,'value' => $row['Date2']); echo form_input($data); ?&gt;</td>
    <td>&lt;?php $data = array('name'=>'Date3','id'=>$row['Date3'],'size'=>20,'value' =>  $row['Date3']); echo form_input($data); ?&gt;</td>
  </tr>
&lt;?php } ?&gt;

</table>

&lt;?php
echo "<div class=submitted>". form_submit('submit','Save Changes')."</div>";
echo form_close();
?&gt;


Messages In This Thread
Need help With Submitting a Dynamic Form - by El Forum - 01-24-2012, 02:41 PM
Need help With Submitting a Dynamic Form - by El Forum - 01-24-2012, 10:08 PM
Need help With Submitting a Dynamic Form - by El Forum - 01-25-2012, 10:51 AM
Need help With Submitting a Dynamic Form - by El Forum - 01-25-2012, 01:03 PM
Need help With Submitting a Dynamic Form - by El Forum - 01-25-2012, 01:12 PM
Need help With Submitting a Dynamic Form - by El Forum - 01-25-2012, 02:31 PM
Need help With Submitting a Dynamic Form - by El Forum - 01-25-2012, 03:15 PM
Need help With Submitting a Dynamic Form - by El Forum - 01-25-2012, 04:25 PM



Theme © iAndrew 2016 - Forum software by © MyBB