我想在“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]));
}
}
答案 0 :(得分:1)
在$delete
变量中有一系列ID后,您可以执行以下操作:
if(is_array($delete) && count($delete) > 0)
{
$this->db->query("DELETE FROM `My_Table` WHERE `id` IN (" . implode(", ", $delete) . ")");
}