2011-08-21 100 views
0

我想用「codeigniter」中的複選框選中後刪除「多行mysql數據庫」,但我的功能不起作用:(我的問題在「function delete()」)。它是什麼?一起刪除幾行mysql數據庫?

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

那麼,什麼是錯誤信息或更詳細的嗎? – sonnb

+0

如果您在for循環之前使用'print_r($ delete);',您會得到什麼?它是否包含你認爲應該的內容? – DaveRandom

回答

1

一旦你的ID陣列在$delete變量,你可以做到以下幾點:

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