delete several row mysql database together?
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]));
}
}
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) . ")");
}
精彩评论