从codeigniter中的2个表中删除记录

时间:2015-04-24 08:39:04

标签: php codeigniter join

如何从2个表中删除codeigniter中的记录? 我想这样做:

我的代码

function delete_dispatchYScoByIdUser($idUser)
{
    $sql = "delete from dispatch
                where scoinstanceid in 
                    (select scoinstanceid from scormvars where iduser = ?)";

    return $this->db->query($sql, array($idUser));
}

3 个答案:

答案 0 :(得分:3)

有很多方法可以做到这一点......

$this->db->delete('dispatch', array('scoinstanceid' => '11'));
$this->db->delete('scormvars', array('iduser' => '11'));

答案 1 :(得分:0)

function deleteRecordsTables($idUser)
{
    $this->db->select('*');
    $this->db->from('dispatch');
    $this->db->join('scormvars','dispatch.scoinstanceid = scormvars.scoinstanceid');
    $this->db->where('dispatch.iduser',$idUser);
    $this->db->delete('dispatch', 'scormvars ');
    return true;
}

答案 2 :(得分:0)

使用此

$this->db->query('delete from dispatch d, scormvars s where d.scoinstanceid = d.scoinstanceid and d.iduser = 11');