Muffinresearch Labs by Stuart Colville

Using PHP to generate select boxes | Comments (3)

Posted in Code on 12th December 2004, 7:10 pm by Stuart

I wrote a little tool to assist with generating select boxes from arrays in PHP. If you have got your form already drawn out in PHP and then you decide you need to use PHP to get the selected item from a stored value in a session or database this can be a real pain. Usually you have to create an array of all of your options now this is fine if you are talking about a few items but if it’s a lot of options this tool creates the array for you. Simply paste in theoptions along with their tags. Comes complete with an example function for creating select boxes from arrays too. See Select Box array generator for more info.

Post Tools

Comments: Add yours

1. On May 9th, 2008 at 6:38 pm Karl said:

Thanks for the code to convert an array to a select list, but could you post the function you use to convert the selectbox to the value-option pairs MD array (Selectbox Converter) used via the form? THAT is what I really need.

Thanks!

http://muffinresearch.co.uk/code/php/select2array/

2. On August 18th, 2009 at 10:49 pm Julie said:

Great script!! I too would love to see the code that builds the value-option multi-dimensional array so I can tweak it. The problem with the existing array output is there needs to be quotes around the array keys:

currently generates:
$multi = array(AF => “Afghanistan”, AL => “Albania”, DZ => “Algeria”, AD => “Andorra”);

correct PHP array syntax should be:
$multi = array(“AF” => “Afghanistan”, “AL” => “Albania”, “DZ” => “Algeria”, “AD” => “Andorra”);

For the most part it would still work but in my case trying to use an array of countries causes a syntax error on country codes “AS” and “DO” because PHP doesn’t see them as strings and tries to interpret them as commands.

3. On August 19th, 2009 at 11:36 pm Stuart Colville said:

@Julie – I’ve updated the script to quote the keys







XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



Using Loggerhead with mod_wsgi|(0)

Here’s a post I wrote over on the Project Fondue Blog about our use of Loggerhead with mod_wsgi under Apache. Loggerhead is the rather nice branch viewer for bazaar branches as used on Launchpad.net.

If you’re not already subscribed to the Project Fondue blog feed then I can recommend it, as there should be some interesting posts coming out of there in the coming months (yes I’m unashamedly biased!).

Ubuntu: Turn off changing workspace with mouse wheel|(1)

I found the changing with the workspace with the mouse wheel really annoying. To disable it go to System => Preferences => CompizConfig (available if the compizconfig-settings-manager package is installed) and uncheck “Viewport Switcher” which is under the “Desktop” heading.

Photos on Flickr

© Copyright 2004-10 Stuart Colville, all rights reserved. May contain traces of Muffin. Powered by WordPress. Hosting by Slicehost.com This page was baked in 0.884s.