删除几行mysql数据库在一起?

时间:2011-08-21 14:37:18

标签: php codeigniter

我想在“codeigniter”中选中复选框后一起删除“几行mysql数据库”,但我的功能不起作用:(我的问题在于“function delete()”)。它是什么?

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])); 
    }
    }

1 个答案:

答案 0 :(得分:1)

$delete变量中有一系列ID后,您可以执行以下操作:

if(is_array($delete) && count($delete) > 0)
{
    $this->db->query("DELETE FROM `My_Table` WHERE `id` IN (" . implode(", ", $delete) . ")");
}