If you have PHP 5 handy, you can convert an associative array (which
in PHP is the equivalent data structure to a JavaScript Hash) into a
hash using the json_encode() function. You have to have a recent
version of PHP (5.2 or greater) to have this function available.
So if you can coerce your database content into an array like this:
$counties = array('Alameda' => array('Parks and Recreation' =>
‘address’,
‘Public Works’ => ‘address’),
//etc…
);
Then running json_encode($counties) would give you the same string
value that I assigned to the JavaScript variable ‘data’ in my example
without you needing to type it all out long-hand.
Many different ways to skin this cat, so if you already have the
content in a database like MySQL, you could also just run a query to
build the picker and use an Ajax callback to return the latest data
each time that picker is changed.
The advantage to the hash is that all the data is in the page, so the
lookup is nearly instantaneous. But for a large dataset, that
advantage might be partially negated by the overall page size when it
includes the entire database in JavaScript notation.
If you can tell me some more about how you have this data stored
currently, and how often it needs to change, I can recommend some
other approaches.
Walter
On Jan 24, 2011, at 9:33 AM, Scott Simons wrote:
man, thats magic!, is there anyway to import/export from a database
or spreadhseet?
freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options