each() assigns four elements... (0 = index), (1 = value), (key = index), (value =
value)
You are concerned with key and value.
So: list ($fieldname, $value) = each($row)
You may not be using $value but you still need to assign the data to a variable. Or
list will only assign $fieldname the numerical
index and not the char index. At least that's from what I understand. Anyone, please
feel free to correct me.
Kristi
Beware of the false gods we sometimes
worship--money, power and fame--for they
are all fleeting, especially in death and often
in mortality.
-Anonymous
----- Original Message -----
From: "Jaxon" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, January 21, 2001 8:07 PM
Subject: [PHP] mysql_fetch_array strangeness
> Hi,
>
> I'm trying to echo out the field names used as key values in a
> mysql_fetch_array:
>
> $link_id = mysql_connect("localhost", "root", $pass);
>
> mysql_select_db("database", $link_id);
>
> $result = mysql_query("select * from lists where id = 1", $link_id);
>
> $rowData = mysql_fetch_array($result);
>
> while (list($fieldName) = each($rowData))
> { echo "$fieldName,"; }
>
> I'm expecting to get this:
>
> id,listname,joinconfirm,leaveconfirm,homepage,author,canjoin,bannedemails,de
> scription,subject,masteremail,
>
> but instead getting this:
>
> 0,id,1,listname,2,joinconfirm,3,leaveconfirm,4,homepage,5,author,6,canjoin,7
> ,bannedemails,8,description,9,subject,10,masteremail,
>
> Why are the index numbers for the array showing up? From the docs,
> mysql_fetch_array should create an array of field names to field values...?
> To make things worse, if I also echo the data:
>
> while (list($fieldName, $fieldValue) = each($rowData))
> { echo "$fieldName,$fieldValue," ;}
>
> Then a value is echoed after both the index number and the field value, eg:
>
> 0,1,id,1,1,testlist,listname,testlist, etc...
>
> What am I doing wrong?
>
> Regards,
> Jaxon
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]