Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/07/2011, 10:24
Krlinhos
 
Fecha de Ingreso: diciembre-2009
Mensajes: 79
Antigüedad: 14 años, 5 meses
Puntos: 1
funcion row()

Hola,

tengo una funcion para coger un registro de la base de datos.

Código PHP:

public function get_registro($tabla,$registro,$campos=null)
    {
        (
is_null($campos))?'':'$query=$this->db->select($campos);';
        
$query $this->db->where($this->imareal->campoClave($tabla),$registro);
        
$query $this->db->get($tabla);
        return 
$query->row();
    } 

Pero quiero saber en el caso de que no haya ningun resultado, y portanto no selecciona ninguno, que me devuelve esta funcion
Porque ya se que si hay me devuelve un unico registro, aunque hubiese mas.

//-------------------------------------------------------------------------------------------------
row()

This function returns a single result row. If your query has more than one row, it returns only the first row. The result is returned as an object. Here's a usage example:

Código PHP:
$query $this->db->query("YOUR QUERY");

if (
$query->num_rows() > 0)
{
   
$row $query->row(); 

   echo 
$row->title;
   echo 
$row->name;
   echo 
$row->body;

Saludos y gracias.

PD.- Si alguien tiene alguna funcion o idea mejor para solo coger un registro, que me diga :)