[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