Re: Help with arrays
| From: | Michael Nolan | Date: | Fri, 12 Mar 2004 09:51:34 +0000 |
| Subject: | Re: Help with arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-180241@lists.php.net to get a copy of this message | ||
Elliot J. Balanza wrote:
I need to make a query to a MySQL database that only has two fields, name & value. That I can do. Then I need to store the values i receive in an array in the form of: $variable['name'] = value; But haven't been able to do it neither with a foreach nor with a do while... Can anyone please assist me?If you mean how do you store all the returned results in an array of name/value pairs, this is how I'd do it: <?php while ($result = mysql_fetch_assoc($query)) {
$variable[$result['name']] = $result['value'];} ?> Don't know what 'value' represents, but it will give you an array something like this: print_r($variable); Array (
[michael] => nolan
[joe] => bloggs
[john] => smith
)
HTH,
Mike