How can I do the dynamic select in Drupal 7 forms? In the following code I call the function players() which returns array of values for option. This values were defined beforehand by hand. How can I load it dynamically from the database?

 $form['officers']['officer'] = array( 
'#title' =&gt; t('Select the officer'), 
'#type' =&gt; 'select', 
'#description' =&gt; t('Please, select the officer'), 
'#options' =&gt; players(), 
'#multiple' =&gt; FALSE, 
'#empty_value' =&gt; ' ',
'#empty_option' =&gt; '- None -',  


);

For example in the "Text Field"  there is property #autocomplete which defines a path where Drupal’s automatically included JavaScript will send HTTP requests using jQuery.

 $form['team_name'] = array( 
'#title' =&gt; t('Name'), 
'#type' =&gt; 'textfield', 
'#description' =&gt; t('Please, insert your name'), 
'#autocomplete_path' =&gt; 'autofillform/teamname' ,


);
And i created the module which handles it.

&lt;?php
function autofillform_menu() {
$items['autofillform/teamname'] = array(  
'title' =&gt; 'Example autocomplete',
'page callback' =&gt; 'autofillform_teamname',  
'access callback' =&gt; TRUE,
'type' =&gt; MENU_CALLBACK,
 );
 return $items;
 }
 function autofillform_teamname($string){
 $matches = array();
 $result = db_query("SELECT name FROM users where lower(name) like '".$string."%'  LIMIT 10");
 foreach ($result as $user) {
 $matches[$user-&gt;name] = check_plain($user-&gt;name);
  } 
 print drupal_json_encode($matches);
 return; 
 }


Are there any possibility to do the same with "Select" ?
In any case take a look at the first answer of this question: i think it's what you are lloking for https://stackoverflow.com/questions/5158744/drupal-7-best-practice-for-a-dynamic-select-list-in-drupal-7