Forum Moderators: coopster

Message Too Old, No Replies

Best way to do dropdown lists.

         

fintan

4:38 pm on Feb 4, 2005 (gmt 0)

10+ Year Member



I've been doing a site for a while now that has several drop down lists in a form. On one form there is the same drop down list repeated 3 times from the same table in a database but with different values.

What would be the best way to repeat the code without repeating all of the code. Basically looking at an more economical way to do things. Would you do a while statement and loop through them or maybe a single array and call it when you need it. Any opions? Thanks

fintan.

mincklerstraat

5:28 pm on Feb 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd put them in an array and make a function that foreaches them but also knows how to add whatever extra values there are that you're needing to put in, since, as you say, the values change from dropdown to dropdown. Since you don't say where it gets these values, I'm afraid I can't be more specific or give an example.

fintan

12:46 am on Feb 5, 2005 (gmt 0)

10+ Year Member



Sorry I ment the name of the select name changes not the values "lack of sleep!".

coopster

8:27 pm on Feb 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You could still put it in a function and just "variable-ize" the name attribute's value.
function buildSelectList($name) 
{
$list = "<select name=\"$name\">";
...
return $list;
}