Codeigniter删除是不允许的,除非它们包含"其中"或"喜欢"条款

时间:2015-04-27 18:39:31

标签: php codeigniter

我有下一个查询并返回此

function delete_dispatchByIdPlataforma($idPlataforma)
{       
    $this->db->delete("delete from dispatch where id_licencia in
    (select id_licencia from licencias where id_plataforma = $idPlataforma)");      
}

所以我尝试了这个:

$this->db->select('id_licencia');
        $this->db->from('licencias');
        $this->db->where('id_plataforma', $idPlataforma);
        $where_clause = $this->db->get_compiled_select();

        #Create main query
        $this->db->where("`id_licencia` IN ($where_clause)", NULL, FALSE);
        $this->db->delete('dispatch');

但现在不返回任何内容,查询也无法执行。

1 个答案:

答案 0 :(得分:0)

// First get the id to delete of my table    
function getIdDispatchToDelete($idPlataforma)
    {
        $this->db->select('ID_dispatch');
        $this->db->from('dispatch');
        $this->db->join('licencias', 'licencias.id_licencia = dispatch.id_licencia');
        $this->db->where('licencias.id_plataforma', $idPlataforma);     
        $query = $this->db->get();
        //echo $this->db->last_query();die();

        if($query){
            if($query->num_rows>0){             
                foreach ($query->result() as $fila){
                    $data[] = $fila->ID_dispatch;           
                }   
                return $data;           
            }
        }else 
            log_message('error', 'No se han encontrado Dispatch a borrar'.$this->db->_error_message().' - '.$this->db->last_query());
    }

// Seccond i did the delete whit the id got it.
     function delete_dispatchByIdPlataforma($idPlataforma)
    {       
        $idDispatch = $this->getIdDispatchToDelete($idPlataforma);
        $this->db->where_in('id_dispatch', $idDispatch);
        $this->db->delete('dispatch');
    }