1
Hello, I have the following function to read mysql BD data.
Here I call ->
$clientes = DBRead('clientes', null, 'nome, telefone1');
Here I display ->
echo $nam = json_encode($clientes);
Upshot:
[
{
"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 makes the following mistake
Notice: Trying to get Property of non-object in...
Warning: Invalid argument supplied for foreach() in...
I tried to put "true" after Code but it didn’t 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;
}
}