Re: how to iterate over fields names with mysql_fetch_assoc
| From: | grahama at siren dot cc | Date: | Sat, 19 Jun 2004 21:58:13 +0000 |
| Subject: | Re: how to iterate over fields names with mysql_fetch_assoc | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-188657@lists.php.net to get a copy of this message | ||
thanks...that is what I had used previously :)
Another php coder had given me a hint that I could just take each incoming row on the fly with $row['artist_name'] without reading everything into an array:
What I had previously was:
while ($row = mysql_fetch_assoc($result))
{
$playlist[] = $row; //read in entire array before doing anything
}
# get row count
$c= count($playlist);
for ($x = 0; $x < $c; $x++)
{
foreach($playlist[$x] as $key => $val)
{
switch ($key){
# if key name is 'artist_name', do somethingcase 'artist_name' : break;
# if key name is 'urlPath', do somethingcase 'urlPath' : break; } } } is there a way to grab the info on the fly without reading the $result into an array ? many thanks as I am on my 3rd week with php.... On Jun 19, 2004, at 1:45 PM, Robin Vickery wrote:
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))<?php while ($row = mysql_fetch_assoc($result)) { foreach ($row as $fieldName => $fieldValue) {{ $fieldName= key($row); echo 'fieldName is: '.$fieldName."\n"; }echo 'fieldName is: '.$fieldName."\n"; echo 'fieldValue is: '.$fieldValue."\n";} } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php