Re: how to iterate over fields names with mysql_fetch_assoc
| From: | Robin Vickery | Date: | Sat, 19 Jun 2004 20:45:08 +0000 |
| Subject: | Re: how to iterate over fields names with mysql_fetch_assoc | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-188648@lists.php.net to get a copy of this message | ||
On Sat, 19 Jun 2004 13:25:54 -0700, grahama@siren.cc <grahama@siren.cc> wrote:
>
> How do I iterate over fields when I perform the below script:
...
> If I write the below code, I only get the first field name of each
> row...which makes sense
> In this case, I get 'artist_name'
>
> while ($row = mysql_fetch_assoc($result))
> {
> $fieldName= key($row);
> echo 'fieldName is: '.$fieldName."\n";
> }
<?php
while ($row = mysql_fetch_assoc($result)) {
foreach ($row as $fieldName => $fieldValue) {
echo 'fieldName is: '.$fieldName."\n";
echo 'fieldValue is: '.$fieldValue."\n";
}
}
?>