Welcome Guest, Not a member yet? Register   Sign In
deleting a row using checkbox
#1

[eluser]sasori[/eluser]
hi, can you guys help me develope the logic for this? yes i mean code snippets
here's my controller code
Code:
public function members_area()
  {
    $this->load->model('member_model');
    $data['q'] = $this->member_model->get_urls();
    $data['title'] = "Members Area";
    $data['main_content'] = 'includes/member_view';
    $this->load->view('includes/template',$data);
  }

here's my model code

Code:
public function get_urls()
  {
    $q = $this->db->get('bookmark');
    return $q;
  }

here's my view code

Code:
<table>
&lt;?php form_open('site/delete'); ?&gt;
<tr><td><b>Bookmark</b></td><td><b>Delete</b></td></tr>
&lt;?php foreach($q->result() as $row):?&gt;
        &lt;?php echo "<tr>"; ?&gt;
        &lt;?php echo "<td>".anchor($row->bm_URL,$row->bm_URL)."</td>"; ?&gt;
        &lt;?php echo "<td>".form_checkbox('delete',$row->bm_URL)."</td>"; ?&gt;
        &lt;?php echo "</tr>"; ?&gt;
&lt;?php endforeach; ?&gt;
</table>

here's the initial look
Code:
http://i47.tinypic.com/24vp81v.jpg

if am gonna place a delete link or button at the bottom, how will i make the "checked"
box be deleted ?
#2

[eluser]saidai jagan[/eluser]
name the check box as array ex.
Code:
&lt;input type=checkbox name=delete[] value=row-&gt;id />
submit the form and get the checked check box values in controller by
Code:
print_r($this->input->post(delete));
#3

[eluser]sasori[/eluser]
hi, the delete is working now, but i got a new problem
all the rows gets deleted even if i checked only 1 box LOL
here's my controller code

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

here's my new model function

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

and here's my view code

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

[eluser]saidai jagan[/eluser]
show the
Code:
print_r($this->input->post(delete));
#5

[eluser]sasori[/eluser]
I added
Code:
&lt;?php echo print_r($this->input->post('delete')); ?&gt;
at the bottom of the view
and it prints "1"
#6

[eluser]Rob Gordijn[/eluser]
try

Code:
&lt;?php echo print_r($this->input->post('delete'),1); ?&gt;
#7

[eluser]sasori[/eluser]
[quote author="Rob Gordijn" date="1264784921"]try

Code:
&lt;?php echo print_r($this->input->post('delete'),1); ?&gt;
[/quote]

i think you mean
Code:
echo print_r($this->input->post('delete',1));

the output is the same, it prints 1
#8

[eluser]radomir_radojevic[/eluser]
Hi ninja Smile

try this

model function:

Code:
public function delete()
{
                
   $delete = $this->input->post('delete');                
    for($i=0;$i<count($delete);$i++) {
    $del_bm_URL = $delete[$i];
    $this->db->where('bm_URL',$del_bm_URL);
        $this->db->delete('bookmark');        
        }                        
  }
#9

[eluser]sasori[/eluser]
thanks for the reply Mr. radomir, I guess you're a real ninja in PHP haha.
#10

[eluser]zend[/eluser]
This to me does not work ... I use the whole code here but the theme will not work ... Not deleted




Theme © iAndrew 2016 - Forum software by © MyBB