Welcome Guest, Not a member yet? Register   Sign In
delete data from database
#1

[eluser]Unknown[/eluser]
I need to pass the id field value to a delete link. This way the whole row will be deleted.
Any help is much appreciated. Thanks.

controller code:
Code:
function delete_record($id){
  $this->load->model('records');
  $id = array('id'=>$this->uri->segment(3));
  $this->records->delete_data($id);
  
  
}

model code:

Code:
function delete_data($id){
  $this->db->where('id',$id);
  if($this->db->delete("users")){
   return true;
  } else return false;

}

view code:

Code:
<?php if(!empty($results)):?>
  <?php foreach($results as $row):?>
  
    <?php
    echo $row->id;
    echo ' | ';
    echo $row->name;
    echo ' | ';
    echo $row->email;
    echo ' | ';
    ?>
    <a href='&lt;?php echo site_url("index.php/home/delete_record", $row-&gt;$id)?&gt;'>Delete</a>
    &lt;?php echo '<br/>';?&gt;
  &lt;?php endforeach?&gt;
&lt;?php endif ?&gt;
#2

[eluser]InsiteFX[/eluser]
Try this:
Code:
<a href='&lt;?php echo site_url("index.php/home/delete_record/".$row-&gt;$id)?&gt;'>Delete</a>

The best way is to use the CI Table class and build your table rows with the delete information.




Theme © iAndrew 2016 - Forum software by © MyBB