Re: Help with arrays
| From: | Elliot J. Balanza | Date: | Fri, 12 Mar 2004 22:17:46 +0000 |
| Subject: | Re: Help with arrays | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-180294@lists.php.net to get a copy of this message | ||
Thank you Michael... That did the trick :D
thank you very very much, it took me three days... and now it seems so damn
easy.
vamp
"Michael Nolan" <michael@michaelnolan.co.uk> escribió en el mensaje
news:c2s16v$r2o$1@sea.gmane.org...
> 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