【问题标题】:How to Delete Specific Multi Records in Codeigniter [closed]如何在 Codeigniter 中删除特定的多记录 [关闭]
【发布时间】:2018-09-02 21:31:27
【问题描述】:

我想使用模型一次删除4,6,8,11,12条记录。我也想知道如何在不使用模型删除以下记录3、5、6、7的情况下做到这一点。

控制器功能

public function delete_data($id,$value){
    $oris = explode("_", $value);
    $oris = array_filter($oris);
    $this->o->delete_data($oris);
}

模型函数

public function delete_data($id){
    $this->db->where('campus_id', $id);
    $this->db->delete('sections');
}

【问题讨论】:

标签: php mysql codeigniter delete-row


【解决方案1】:

4,6,8,11,12 条记录已删除

public function delete_data($id){
    $this->db->where_in('campus_id', $id);
    $this->db->delete('sections');
}

3,5,6,7 条记录未删除

public function delete_data($id){
    $this->db->where_not_in('campus_id', $id);
    $this->db->delete('sections');
}

哇,我明白了..

【讨论】:

    【解决方案2】:

    你的模型

    public function delete_record() //You can pass ID as a parameter here
    {
        $this->db->where('column-name', 'your-id'); //id can be 4, 6, 8, 11, 12
        return $this->db->delete('table-name');
    }
    

    【讨论】:

    • 谢谢兄弟 :) 你解决了我的问题...
    • @AliHaider 如果工作接受答案
    猜你喜欢
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 2012-04-23
    • 1970-01-01
    • 2018-01-17
    • 1970-01-01
    • 2022-01-28
    • 1970-01-01
    相关资源
    最近更新 更多