Jump to content

CI checkbox for deleting rows


sasori

Recommended Posts

hi i got a problem, i dunno why my code deletes all the rows when I only tick 1 checkbox, i don't really get it LOL

please help me with this

 

here's my controller code

 

  public function delete()
  {
    $q = $this->input->post('delete');
    if(isset($q))
    {
      $this->member_model->delete($q);
      $this->members_area();
    }
    else{
      redirect('site/members_area');
    }
  }

 

here's my model code

 

  public function delete($url)
  {
    $this->db->where('bm_URL',$url);
    $q = $this->db->delete('bookmark');
    return $q;
  }

 

view code

 

<tr><td><b>Bookmark</b></td><td><b>Delete</b></td></tr>
<?php foreach($q->result() as $row):?>
        <?php echo "<tr>"; ?>
        <?php echo "<td>".anchor('site/delete'.$row->bm_URL,$row->bm_URL)."</td>"; ?>
        <?php echo "<td>".form_checkbox('delete[]',$row->bm_URL)."</td>"; ?>
        <?php echo "</tr>"; ?>
<?php endforeach; ?>
</table>
<br />
<hr />
<?php echo anchor('site','Home'); ?>  |  <?php echo anchor('site/addbm','Add BM'); ?>  |
<?php echo anchor('site/delete','Delete BM'); ?>   |   <?php echo anchor('user/changepass','Change Password'); ?><br />
<?php echo anchor('site/recommend','Recommend URLs to me'); ?>   |   <?php echo anchor('user/logout','Log out'); ?><br />

 

Link to comment
https://forums.phpfreaks.com/topic/190340-ci-checkbox-for-deleting-rows/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.