Re: mysql_fetch_array strangeness

From: Date: Mon, 22 Jan 2001 03:15:06 +0000
Subject: Re: mysql_fetch_array strangeness
References: 1  Groups: php.general php.general 
Request: Send a blank email to php-general+get-35941@lists.php.net to get a copy of this message
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" <jaxon@salamander.net> To: <php-general@lists.php.net> 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: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#35941) next »