Sunday 17 May 2015

Multiple Update in codigniter

View

<form name="form1" method="post" action="<?php echo base_url('route/update'); ?>">
<table class="table table-striped" id="table-example">
<thead>
<tr>
<th  class="text-center">Rendering engine</th>
<th class="text-center">Browser</th>
<th class="text-center">Platform(s)</th>
<th class="text-center">Engine version</th>
<th class="text-center">CSS grade</th>
</tr>
</thead>
<tbody align="center">
<?php 
foreach($row as $rows){
$id=$rows->id;
?>
   <input type='hidden' name='ids[]' value='<?php echo $id;?>' />
<tr class="gradeU">

<td><input type='text' name='city[]' value='<?php echo $rows->route_city;?>' /></td>
<td><input type='text' name='name[]' value='<?php echo $rows->RouteName;?>' /></td>
<td>-</td>
<td class="center"><?php echo "<a href=".base_url().'route/editroute/'.$id.">".$id."</a>";?></td>
<td class="center"><?php echo "<a href=".base_url().'route/deleteroute/'.$id.">".$id."</a>";?></td>
</tr>
<?php 
}
?>
</tbody>
</table>
<input type="submit" name="submit" value="Submit" />
<input type="reset" name="Reset" value="Reset" />
</form>

Model

function getRoute(){
$data=$this->db->query("select * from route_master");
return $data->result();
}


Controller

//for display data

public function index()
{
$data['row']=$this->model_registration->getRoute();
$this->load->view("registration/view_route",$data);
}

//for update

public function update(){
$data  = array();
for($i = 0; $i < count($_POST['ids']); $i++) {
    if($_POST['ids'][$i] != '') {
        $data[] = array(
            'id' => $_POST['ids'][$i],
            'route_city' => $_POST['city'][$i]
            );
    }
}
$linksCount = count($data);
if($linksCount) {
   // $this->db->where('id','id');
    //$this->db->insert_batch('route_master', $data);
    $this->db->update_batch('route_master', $data, 'id');
}
redirect('route/index');
}

No comments:

Post a Comment

Installation of Drop Box API on Codigniter

As with the YouTube API the first step in getting this sucker setup is getting a developer key by visiting  https://www.dropbox.com/develop...