Maybe there is a better way to do this. What I'm trying to do is generate on the the fly a Select box for a form based off of a SQL query.
Right now the code below works, however a few oddities. The default value specified below does not show up. I'm wondering does this have to be a valid result returned? Also my drop down shows the SQL results, however the foreach loop seems to go an extra iteration which causes a stray value of 2 to return to the list. Is there a way to stop that. And of course if I'm going about the structuring of this all wrong please let me know.
Thanks
$sqlplatform = "SELECT vid, name FROM {taxonomy_vocabulary} WHERE vid >= 4";
$i = 0;
$result = db_query($sqlplatform);
foreach ($result as $row){
$option[] = $row->name;
$i++;
}
$form['multiple_dev']['platform'] = array(
'#type' => 'select',
'#title' => t('Select a Platform'),
'#options' => array(
$i => t($option),
),
'#default_value' => 'Platform Type',
);