1
I’m developing a project, in which I need to dynamically take the data that is registered in the database. To read this data, I have this function:
// Lê registros
function DBRead($table, $params = null, $fields = '*'){
$table = DB_PREFIX.'_'.$table;
$params = ($params) ? " {$params}" : null; // Caso não haja parâmetros, remove espaço em branco no final da Query
$query = "SELECT {$fields} FROM {$table}{$params}";
$result = DBExecute($query);
if (!mysqli_num_rows($result))
return false;
else{
while($res = mysqli_fetch_array($result)){
$data[] = $res;
}
return $data;
}
}
She returns me a array
, with various indices, and within these indices comes another array
, with more indexes. Return example:
array
0 =>
array
0 => string 'Postagem de testes' (length=18)
'titulo' => string 'Postagem de testes' (length=18)
1 => string 'Welington Braga' (length=15)
'autor' => string 'Welington Braga' (length=15)
1 =>
array
0 => string 'Huheuhehue' (length=10)
'titulo' => string 'Huheuhehue' (length=10)
1 => string 'Welington Braga' (length=15)
'autor' => string 'Welington Braga' (length=15)
I don’t understand why this function is returning error:
"mysql_fetch_array() expects Parameter 1 to be Resource, array Given in":
$postagens = DBRead('postagens', 'WHERE status = 1', 'titulo, autor, conteudo');
while ($dados = mysql_fetch_array($postagens)){
echo '.$dados['titulo']'; //Imprime os dados que preciso
}
Functional solution, however, needed the reading function to be given in the post.
– Daniel Bonifácio