note 94602 modified in mysqli-result.fetch-assoc by danbrown
| From: | danbrown@php.net | Date: | Fri, 13 Nov 2009 19:57:29 +0000 |
| Subject: | note 94602 modified in mysqli-result.fetch-assoc by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162878@lists.php.net to get a copy of this message | ||
[This describes the syntax difference in calling $result->fetch_assoc().]
<?php
/* fetch associative array works inside a while loop */
while ($row = $result->fetch_assoc()) {
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
}
// works
/* fetch associative array doesn't work inside a foreach */
foreach($result->fetch_assoc() as $row) {
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
}
// fails
?>
--was--
/* fetch associative array works inside a while loop */
while ($row = $result->fetch_assoc()) {
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
}
// works
/* fetch associative array doesn't work inside a foreach */
foreach($result->fetch_assoc() as $row) {
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
}
// fails
http://php.net/manual/en/mysqli-result.fetch-assoc.php