Date: 06/20/02
- Next message: Martin Clifford: "[PHP-DB] Resetting auto_incremented values"
- Previous message: Mike Hughes: "[PHP-DB] array problem"
- In reply to: Mike Hughes: "[PHP-DB] array problem"
- Next in thread: Jason Wong: "Re: [PHP-DB] array problem"
- Reply: Jason Wong: "Re: [PHP-DB] array problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 <email protected>
-----Original Message-----
From: Mike Hughes [mailto:m.hughes <email protected>]
Sent: 20 June 2002 16:12
To: php-db <email protected>
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-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
- Next message: Martin Clifford: "[PHP-DB] Resetting auto_incremented values"
- Previous message: Mike Hughes: "[PHP-DB] array problem"
- In reply to: Mike Hughes: "[PHP-DB] array problem"
- Next in thread: Jason Wong: "Re: [PHP-DB] array problem"
- Reply: Jason Wong: "Re: [PHP-DB] array problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

