0

I want to delete "several row mysql database" together after select with checkbox in "codeigniter", but my function not work:(my problem is in "function delete()"). What is it?

function delete(){
    $delete = $this->input->post('delete'); // this is array => "delete[]" . value this is "id" it row in database.
    for($i=0;$i<count($delete);$i++) {
        $this->db->delete('My_Table', array('id' => $delete[$i])); 
    }
    }
2
  • 1
    So what is error message or more detail please? Commented Aug 21, 2011 at 14:41
  • What do you get if you print_r($delete); before the for loop? Does it contain what you think it should? Commented Aug 21, 2011 at 14:43

1 Answer 1

1

Once you have an array of ID's in your $delete variable, you can do the following:

if(is_array($delete) && count($delete) > 0)
{
    $this->db->query("DELETE FROM `My_Table` WHERE `id` IN (" . implode(", ", $delete) . ")");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.