How to get the default value of radio button from database? I have 5 check-box. For each check-box, 5 radio buttons get generated. These radios value get saved to database. Now what I want is, when I select check-box, and if the selected check-box has some database value already saved in database, that radio button should show saved database value, mean to say, it should be shown selected.
5 check-box are like:
1. A
2. B
3. C
4. D
5. C

All check-box has radio options like:
Male or Female

If(say) I choose "Male" for "A" and submit my form. when I again go to that form and choose "A", "male" radio button should be shown selected.

some code implementation:

foreach ($check-box-options as $key =&gt; $value) {

        $form['radio_'.$key] = array(
            '#type' =&gt; 'radios',
            '#title' =&gt; t('abc'),
            '#options' =&gt; $filter_radio_options,
            '#default_value'=&gt; ???,
            '#states' =&gt; array(
                'visible' =&gt; array(
                    ':input[name="filter_criteria_options['.$key.']"]' =&gt; array('checked' =&gt; TRUE),
                ),
            ),
        );
}


$check-box-options is an array of check-box A,B,C,D,E. For each check-box, I have radios.

$serialized = unserialize($radio_buttons_database_values);


$serialized contains all selected radio button values. If I replace $check-box-options with $serialized, I got correct radio button selected as default, but if I loop $serialized as nested inside $check-box-options, it is throwing last selected value from database for every check-box. I am not getting the exact problem with my code or approach.

Can anyone please help me understanding the exact problem behind this?
As the radios are separate field in itself, default value should be as easy as follow

foreach ($check-box-options as $key =&gt; $value) {
        //A. A function to query database to get default value
        $default_value = _my_module_helper_get_default_radio_option($key);

        //B. Or if its a system setting form, all values are inside the variables, in that case all you have to do is variable_get()
        $default_value = variable_get('radio_'.$key);

        // Depending on form type use option A or B.

        $form['radio_'.$key] = array(
            '#type' =&gt; 'radios',
            '#title' =&gt; t('abc'),
            '#options' =&gt; $filter_radio_options,
            '#default_value'=&gt; $default_value,
            '#states' =&gt; array(
                'visible' =&gt; array(
                    ':input[name="filter_criteria_options['.$key.']"]' =&gt; array('checked' =&gt; TRUE),
                ),
            ),
        );
}

// In case option A is what you needed.
function _my_module_helper_get_default_radio_option($key) {
  return db_select('your_table','yt')
         -&gt;fields('yt',array('field_name'))
         -&gt;condition('yt.field_is',$key,'=')
         -&gt;exectue()
         -&gt;fetchField();

 }