RE: [PHP-DB] array problem

From: Date: Thu, 20 Jun 2002 15:26:17 +0000
Subject: RE: [PHP-DB] array problem
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-19906@lists.php.net to get a copy of this message
By passing a second parameter to mysql_fetch_array, MYSQL_ASSOC This means you only get back an array with the values indexed by fieldname. HTH, Richy ========================================== Richard Black Systems Programmer, DataVisibility Ltd - http://www.datavisibility.com Tel: 0141 435 3504 Email: rblack@datavisibility.co.uk -----Original Message----- From: Mike Hughes [mailto:m.hughes@geog.ucl.ac.uk] Sent: 20 June 2002 16:12 To: php-db@lists.php.net Subject: [PHP-DB] array problem Hi, I am carrying out MySQL queries and putting the results into arrays for easy handing in PHP. However, I have a small problem. I want to automatically display the query result by printing out the array using a simple for each loop like so: $result = mysql_query($query); $row = mysql_fetch_array($result); foreach($row as $key => $val) { if ($val != NULL){ echo "$key is set to $val<br>"; } } but when I do this I get two entries for each field, one with the numerical key and the other with the field name key. 0 is set to field1data field1name is set to field1data 1 is set to field2data field1name is set to field2data etc .. How to just get the output with the field names? Mike -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.db (#19906) next »