SV: [PHP-DB] how to iterate over fields names with mysql_fetch_assoc
| From: | Henrik Hornemann | Date: | Mon, 21 Jun 2004 08:48:41 +0000 |
| Subject: | SV: [PHP-DB] how to iterate over fields names with mysql_fetch_assoc | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-34851@lists.php.net to get a copy of this message | ||
Try rhis:
while ($row = mysql_fetch_assoc($result))
{
foreach ($row as $fieldName -> $value)
echo 'fieldName is: '.$fieldName."\n";
}
hth Henrik Hornemann
-----Oprindelig meddelelse-----
Fra: grahama@siren.cc [mailto:grahama@siren.cc]
Sendt: 19. juni 2004 22:26
Til: php-general@lists.php.net; php-db@lists.php.net
Emne: [PHP-DB] how to iterate over fields names with mysql_fetch_assoc
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 :)
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php