Answer the question
In order to leave comments, you need to log in
Why does it throw an Illegal string offset error when using foreach?
There is a code:
$query = $mysqli->query("SELECT * FROM `users` ORDER BY `id` DESC LIMIT 10");
$row = $query->fetch_array();
foreach ( $row as $user){
echo $user['id'];
}
Warning: Illegal string offset 'id' in E:\openserv\OpenServer\domains\kolbasa\index.php on line 165
1
Warning: Illegal string offset 'id' in E:\openserv\OpenServer\domains\kolbasa\index.php on line 165
1
Warning: Illegal string offset 'id' in E:\openserv\OpenServer\domains\kolbasa\index.php on line 165
4
Warning: Illegal string offset 'id' in E:\openserv\OpenServer\domains\kolbasa\index.php on line 165
4
Warning: Illegal string offset 'id' in E:\openserv\OpenServer\domains\kolbasa\index.php on line 165
4
Warning: Illegal string offset 'id' in E:\openserv\OpenServer\domains\kolbasa\index.php on line 165
4
Warning: Illegal string offset 'id' in E:\openserv\OpenServer\domains\kolbasa\index.php on line 165
1
Warning: Illegal string offset 'id' in E:\openserv\OpenServer\domains\kolbasa\index.php on line 165
1
Answer the question
In order to leave comments, you need to log in
Selects one row from the result set and puts it in an associative array, regular array, or both
$row
work as if there are not columns of one line , but all lines (although you even have a variable named correctly).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question