Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #12024
| From | tony@mountifield.org (Tony Mountifield) |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: from mysql in associative array |
| Date | 2013-11-29 15:40 +0000 |
| Organization | Software Insight Ltd., Winchester, UK |
| Message-ID | <l7achb$ab9$2@softins.softins.co.uk> (permalink) |
| References | <l7abvs$k7s$1@dont-email.me> <l7acaj$ab9$1@softins.softins.co.uk> |
I wrote:
> In article <l7abvs$k7s$1@dont-email.me>,
> Knut Krueger <knut.krueger@usa.com> wrote:
> > Hi to all, whats the best was to get to get one of two colums of an
> > database query in an array as the names of the associative array
> >
> > means
> > mysql table
> > id value
> > 1 green
> > 2 red
> > 3 blue
> > ....
> >
> >
> > should be
> >
> > $array = array ( 'green ' => '1',
> > 'red ' => '2',
> > 'blue ' => '3' );
>
> I would do something like:
>
> $array = array();
>
> $sh = mysql_query("SELECT id,value FROM mytable", $db);
> if ($sh) {
> while ($ob = mysql_fetch_object($sh)) {
> $array[$ob->value] = $ob->id;
> }
> $sh->finish();
Of course, that should be mysql_free_result($sh);
That's what I get for flipping between PHP and Perl DBI !
> }
>
> Cheers
> Tony
> --
> Tony Mountifield
> Work: tony@softins.co.uk - http://www.softins.co.uk
> Play: tony@mountifield.org - http://tony.mountifield.org
--
Tony Mountifield
Work: tony@softins.co.uk - http://www.softins.co.uk
Play: tony@mountifield.org - http://tony.mountifield.org
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
from mysql in associative array Knut Krueger <knut.krueger@usa.com> - 2013-11-29 16:31 +0100
Re: from mysql in associative array tony@mountifield.org (Tony Mountifield) - 2013-11-29 15:36 +0000
Re: from mysql in associative array tony@mountifield.org (Tony Mountifield) - 2013-11-29 15:40 +0000
Re: from mysql in associative array The Natural Philosopher <tnp@invalid.invalid> - 2013-11-29 16:47 +0000
Re: from mysql in associative array Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-29 14:06 -0500
Re: from mysql in associative array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-29 21:29 +0100
Re: from mysql in associative array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-29 22:26 +0000
Re: from mysql in associative array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-29 23:36 +0100
Re: from mysql in associative array Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-29 23:56 +0000
Re: from mysql in associative array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-30 00:30 +0000
Re: from mysql in associative array Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-29 20:29 -0500
Re: from mysql in associative array tony@mountifield.org (Tony Mountifield) - 2013-11-30 13:35 +0000
Re: from mysql in associative array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-30 15:28 +0100
csiph-web