Hello, I have the following function to read DB data mysql.
Here I call - >
$clientes = DBRead('clientes', null, 'nome, telefone1');
Here I display - >
echo $nam = json_encode($clientes);
Result:
[
{
"nome":"Davi",
"telefone1":"654654"
},
{
"nome":"Davi",
"telefone1":null
},
{
"nome":"Davi",
"telefone1":null
}
]
Here I try to manipulate the results separately:
$jsonObj = json_decode($nam);
$dados = $jsonObj->nome;
foreach ( $dados as $e ) { echo "nome: $e->nome "; }
but gives the following error
Notice: Trying to get property of non-object in ...
Warning: Invalid argument supplied for foreach () in ...
I tried to put ", true" after the decode but it did not work.
Does anyone have an idea how I can handle this data?
Here the Search function in another file->
function DBRead($table, $params = null, $fields = '*'){
$table = $table;
$params = ($params) ?" {$params}" : null;
$query = "SELECT {$fields} FROM {$table}{$params}";
$result = DBExecute($query);
if(!mysqli_num_rows($result))
return false;
else{
while ($res = mysqli_fetch_assoc($result)){
$data[] = $res;
}
return $data;
}
}