Re: Newbie Q on Arrays?

From: Date: Mon, 21 Oct 2002 10:12:31 +0000
Subject: Re: Newbie Q on Arrays?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-120713@lists.php.net to get a copy of this message
The array will only be valid due the current execution of your script. So if you are only querying the database once then storing the data in a array might not be useful to you... But if you do want to use Arrays a associate array sounds prefect here (I love PHP), basically set it up like this: myArray['apples'] = 1; myArray['pears'] = 2; myArray['oranges'] = 3; This can just as easily be done in a loop reading all the records from the db. Now if you want to know what number pears is you just use myArray['pears'], for example: echo myArray['pears']; will display 2. Hope this helps Andrew ----- Original Message ----- From: "Tony Crockford" <tonyc@boldfish.co.uk> To: "Php-General@Lists. Php. Net" <php-general@lists.php.net> Sent: Monday, October 21, 2002 11:02 AM Subject: [PHP] Newbie Q on Arrays? > Hi all, > > I've got a MySQL database with lookup tables > > i.e numerical reference and alphanumeric value > > e.g. > > ref - title > 1 - Apples > 2 - pears > 3 - oranges > > now if I want the title that matches the ref I'm currently doing an SQL > query each time. > > I'm sure this isn't efficient, I've been reading about Arrays, but not > quite understanding them. > > could I do one trip to the database, read the ref and title pairs, store > them in an array and whenever I need a title just search the array for > title that matches the ref? > > If so, what's the PHP syntax? code samples or tutorial links greatly > appreciated. > > Many thanks > > Tony > > > -- > http://www.maccaws.org/ > [Making A Commercial Case for Adopting Web Standards] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#120713) next »