Welcome Guest, Not a member yet? Register   Sign In
function in model return null
#1

[eluser]dexter21[/eluser]
Hi, i have a function in a model for making form fields of a sql statement :
Code:
function query2($sql,$tabla)
    {
        $query = $this->db->query($sql);

        if ($query->num_rows() > 0)
        {
            $objeto = null;
            $objeto->campos = $query->field_data();
            
            $valores = $query->row();
            
            foreach($objeto->campos as $key=>$campo)
            {
            
                foreach($valores as $nombre=>$valor)
                   {
                
                       if($nombre == $campo->name)
                       {

                           $campo->valor = $valor;
                        $campo->nombre=$campo->name;
                        
                        
                        echo "campo->nombre:".$campo->nombre."<br>";                                            
                        echo "campo->valor:".$campo->valor."<br>";
                    
                           break;  
                        
                       }
                    
                   }

           }
        }
        else
        {
            $objeto = null;
            $objeto->campos = $query->field_data();
            foreach($objeto->campos as $campo)
            {
                   $campo->valor = null;
                   $campo->nombre = $this->traduceCampo($tabla,$campo->name);
            }
        }

        
              
       return $objeto;
    }

the echo inside if ,print nombre and valor rightly, but after close the if those values are null, and of course the values of the return are also null.

i get $objeto values from a view with:
Code:
foreach($registro->campos as $campo)
    {
        
            echo "campo->type:".$campo->type."<br>";
            echo "campo->name:".$campo->name."<br>";
            echo "campo->nombre:".$campo->nombre."<br>";
            echo "campo->valor:".$campo->valor."<br>";
    
    }


//i get error
//Message: Undefined property: nombre
//Message: Undefined property: valor

Anyone could help me plz


many thanks


Messages In This Thread
function in model return null - by El Forum - 05-31-2008, 12:29 PM
function in model return null - by El Forum - 05-31-2008, 04:11 PM
function in model return null - by El Forum - 05-31-2008, 04:48 PM
function in model return null - by El Forum - 06-01-2008, 04:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB