Making Dropdown boxes from array.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dast
Forum Newbie
Posts: 4
Joined: Mon Mar 17, 2008 6:59 am

Making Dropdown boxes from array.

Post by dast »

I have a load of the array entries below, what I need to know is how to loop through them making the 'internal name' the id for a select box and the 'options' the options for the select box. Any help would be greatly appreciated!!

Code: Select all

                                                       $data['profile:details'][] = (object)(array(
                                                                    "name" => __gettext("Are you circumsized? "),
                                                                    "internal_name" => "circumsized",
                                                                    "field_type" => "select",
                                                                    "options" => array(
                                                                        'yes'=>__gettext('Yes'),
                                                                        'no'=>__gettext('No'),
                                                                        'na'=>__gettext('Not Applicable')),
                                                                    "description" =>"",
                                                                    "user_type" => "person",
                                                                    "category" => __gettext("Your Personal Information"),
                                                                    "col1" => true,     
                                                                    "invisible" => false,
                                                                    "required" => false,
                                                                    ));
                                                                    
                                                                    
                                                        $data['profile:details'][] = (object)(array(
                                                                    "name" => __gettext("What type of body hair do you have?"),
                                                                    "internal_name" => "body_hair",
                                                                    "field_type" => "select",
                                                                    "options" => array(
                                                                        'yes'=>__gettext('Yes'),
                                                                        'no'=>__gettext('No'),
                                                                        'na'=>__gettext('Not Applicable')),
                                                                    "description" =>"",
                                                                    "user_type" => "person",
                                                                    "category" => __gettext("Your Personal Information"),
                                                                    "col1" => true,     
                                                                    "invisible" => false,
                                                                    "required" => false,
                                                                    ));
sureshmaharana
Forum Commoner
Posts: 30
Joined: Thu Jul 03, 2008 4:20 am
Contact:

Re: Making Dropdown boxes from array.

Post by sureshmaharana »

Check this one:

$data['profile:details'][] = (object)(array(
"name" =>"Are you circumsized? ",
"internal_name" => "circumsized",
"field_type" => "select",
"options" => array(
'yes'=>'Yes',
'no'=>'No',
'na'=>'Not Applicable'),
"description" =>"",
"user_type" => "person",
"category" => "Your Personal Information",
"col1" => true,
"invisible" => false,
"required" => false,
));

$data['profile:details'][] = (object)(array(
"name" =>"What type of body hair do you have?",
"internal_name" => "body_hair",
"field_type" => "select",
"options" => array(
'yes'=>'Yes',
'no'=>'No',
'na'=>'Not Applicable'),
"description" =>"",
"user_type" => "person",
"category" => "Your Personal Information",
"col1" => true,
"invisible" => false,
"required" => false,
));





while (list($key, $val) = each($data['profile:details']))
{
?>
<select size="1" name="D1" style="width: 140; height: 22" id="<?=$data['profile:details'][$key]->internal_name;?>">
<?
while (list($optionkey, $optionval) = each($data['profile:details'][$key]->options))
{
?>
<option value="<?=$optionkey?>"><?=$optionval?></option>
<?
}
?>
</select>
<?
}
Post Reply