I have a small problem with my mysqli related function. Here is the code:
$query = "SELECT * FROM uploads";
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
return $row;
}
The problem is that when I use this function $row appears to be an array, but with only the first value from the query result in it.
But if I try to return var_dump($row) instead, function displays array as expected, with all the values from the query result.
Can you please explain why is this happening and how to return an array with complete query result correctly.
Thanks!
解决方案$data = array();
$query = "SELECT * FROM uploads";
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
}
return $data;