[eluser]dexter21[/eluser]
hi , iam trying to get all fields names and values from a table . i've made a custom query that return an array of elements.if i print $campo->valor, and $campo->nombre i obtain the results but if i call to function in a view it said that campo->nombre and campo->valor dont exisxt;
basicly i use following function as:
Code:
$sql = "select * from news";
$sql .= " where nCodnoticia = 1";
registro=$this->db->query2($sql,$this->tabla);
$registro->campos[0]->type ->ok it print it
$registro->campos[0]->valor ->it give me an error, dont exist
any could help me plz ?
following function:
Code:
function query2($sql,$tabla)
{
$query = $this->query($sql);
if ($query->num_rows() > 0)
{
$objeto = null;
$objeto->campos = $query->field_data();
$valores = $query->row();
foreach($objeto->campos as $campo)
{
echo $campo->name."<br>";
echo $campo->type."<br>";
echo $campo->max_length."<br>";
echo $campo->primary_key."<br>";
foreach($valores as $nombre=>$valor)
{
if($nombre == $campo->name)
{
$campo->valor = $valor;
$campo->nombre = $this->traduceCampo($tabla,$campo->name);
echo "campo->valor:".$campo->valor."<br>";
echo "campo->nombre:".$campo->nombre."<br>";
break;
}
}
}
}
else
{
$objeto = null;
$objeto->campos = $query->field_data();
foreach($objeto->campos as $campo)
{
$campo->valor = null;
$campo->nombre = $campo->name;
}
}
//echo var_dump($objeto);
return $objeto;
}