Something easier:
while ($row=mysql_fetch_assoc($result)) {
foreach ($row as $k=> $val) {
switch ($k) {
case 'artist_name':
// do sometihing here, you may want to use $val;
break;
case 'urlPath':
// do something here you may want to use $val;
break;
default:
// do default action in case none is matching case value
(default is optional)
}//end switch
}//end foreach
}//end while
You need to go through the $result anyway, remember that $result is a
"resource" type it is wath is called a "recordset" in asp, it's kind of
object you have to "manipulate" to extract information from.
Franciccio
<[EMAIL PROTECTED]> ha scritto nel messaggio
news:[EMAIL PROTECTED]
> 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 something
> case 'artist_name' :
>
> break;
>
> # if key name is 'urlPath', do something
> case '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, [EMAIL PROTECTED]
> > <[EMAIL PROTECTED]> 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";
> > }
> > }
> > ?>
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php