Ver Mensaje Individual
  #2 (permalink)  
Antiguo 20/01/2016, 09:37
Avatar de bymorr
bymorr
 
Fecha de Ingreso: septiembre-2012
Mensajes: 118
Antigüedad: 11 años, 7 meses
Puntos: 9
Respuesta: Subconsulta en codeigniter

Si no le pasas parámetros.

Código PHP:
Ver original
  1. function consulta(){        
  2.     $sql = "select Nombre,id,Observacion from deta_call_gestion a where id = (select max(id)from deta_call_gestion b where a.rut = b.rut)";
  3.     $query= $this->db->query($sql);
  4.     if($query->num_rows() > 0){
  5.         return $query->result();
  6.     }
  7. }

si le pasas parametros.

Código PHP:
Ver original
  1. function consulta($rut){        
  2.     $sql = "select Nombre,id,Observacion from deta_call_gestion a where id = (select max(id)from deta_call_gestion b where a.rut = ".$rut.")";
  3.     $query= $this->db->query($sql);
  4.     if($query->num_rows() > 0){
  5.         return $query->result();
  6.     }
  7. }

o bien

Código PHP:
Ver original
  1. public function consulta($rut){
  2.         $sql="select Nombre,id,Observacion from deta_call_gestion a where id = (select max(id)from deta_call_gestion b where a.rut =?  ";
  3.     return $this->db->query($sql, array($rut))->result_array();
  4.     }