Why does the Mysqli class use a foreach to fetch only one row, while the while loop pulls out multiple rows of data?
I am a novice, there is a problem please help, is to use the Mysqli class, the data table test has 5 rows of data, with the Foreach function can only take out the first row, the others are not taken out, while using while can be removed 5 rows, why?
$mysqlii =new mysqli ("localhost", "root", "root", "test");
$sql = "SELECT * from user";
$rs = $mysqlii->query ($sql, Mysqli_store_result);
foreach ($rs->fetch_row () as $key = + $v 2) {
Print_r ($v 2); Only the first row of data can be fetched here
}
while (list ($a, $b, $c, $d) = $rs->fetch_array ()) is able to remove 5 rows or all of the data
//
echo $a. " + ". $b." + ". $c."
";
?>
------Solution--------------------
foreach ($rs->fetch_row () as $key = + $v 2) {
Print_r ($v 2); Only the first row of data can be fetched here
}
The function of this write is to loop the data for all columns of the first row.
The $rs->fetch_row () returns an array.
------Solution--------------------
foreach ($rs->fetch_row () as $key = + $v 2) {
Print_r ($v 2); Only the first row of data can be fetched here
}
foreach ($rs->fetch_array () as $key = + $v 2) {
Print_r ($v 2); Only the first row of data can be fetched here
}
------Solution--------------------
References:
References:
foreach ($rs->fetch_row () as $key = + $v 2) {
Print_r ($v 2); Only the first row of data can be fetched here
}
The function of this write is to loop the data for all columns of the first row.
The $rs->fetch_row () returns an array.
I've also considered a two-dimensional array, with
foreach ($rs->fetch_row () as ...
This is still not right!
foreach ($rs->fetch_row () as $v 2)
When you print $v2, the data for each column in the first row is printed,
is a string, not an array.
In this case, you are going to get an error if you foreach ($v 2 as $v 3)!
while ($ary = $rs->fetch_row ())
{
foreach ($ary as $key = + $v 2) {
Print_r ($v 2);
}
}
This is possible.