how to iterate over fields names with mysql_fetch_assoc
| From: | grahama at siren dot cc | Date: | Sat, 19 Jun 2004 20:25:54 +0000 |
| Subject: | how to iterate over fields names with mysql_fetch_assoc | ||
| References: | 1 | Groups: | php.db php.general |
| Request: | Send a blank email to php-general+get-188643@lists.php.net to get a copy of this message | ||
How do I iterate over fields when I perform the below script:
each row has: artist_name,urlPath,biography as fields
while ($row = mysql_fetch_assoc($result))
{
# if the current field name is 'artist_name', do something
switch($GetCurrentFieldNameintheCurrentRow)
{
case $row[ 'field name is now: artist_name']
//do something
break;
}
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";
}
many thanks :)