Submit button to filter data from table select by selecting on list select i'm new on drupal, i've create a module that shows a form (with tableselect, list select and a submit button) the tableselect shows data from the database, but i want to filter what i want to see on the table by selecting what i want from the list select and submit. i've create the submit function (it contains the query with condition) and when i use dsm($form['tableselect'] everything works (filter works), but how can i show the result's select on the tableselect ? because it doesn't change

here's my form : 

$form['options_state'] = array(
    '#type' =&gt; 'value',
    '#value' =&gt; array (
        'all'=&gt;t('All'),
        'Valid'=&gt;t('Valid'),
        'published'=&gt;t('published'),
        'not published'=&gt;t('not published')

        )

    );


$form['state_book'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; t('state :'),                     
    '#options' =&gt; $form['options_state']['#value'],        
);


// filter submit button

$form['filter'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('filter')                
    );


and this is my table select (the first one shows all records) ;

$header  = array(
    'book_title' =&gt; t('title'),
    'book_state' =&gt; t('state'),   
);

    $sql = db_select('field_data_field_title','ta');
    $sql-&gt;join('field_data_field_state','st','st.entity_id = ta.entity_id');


    $sql
        -&gt;fields('ta', array('field_titre_en_arabe_value','entity_id'))       
        -&gt;fields('st',array('field_state_value'));
        $result = $sql-&gt;execute();


    $rows = array();



foreach ($result as $res){ 

$rows [] = array(
        'book_title' =&gt; l($res-&gt;field_title_value, 'node/'.$res-&gt;entity_id),
        'book_state' =&gt; $res-&gt;field_state_value           
      );  

}

$form['table1'] = array(
    '#type' =&gt; 'tableselect',
    '#header' =&gt; $header,
    '#options' =&gt; $rows,
    '#empty' =&gt; t('empty !'),

);


return $form;


}

table1 works, but it shows all records (book published and not published)
now here's my submit function :

function book_form_submit($form, &amp;$form_state){



$cond = $form_state['values']['state_book'];


$header  = array(
    'book_title' =&gt; t('title'),
    'book_state' =&gt; t('state'),
);

$sql = db_select('field_data_field_title','ta');
$sql-&gt;join('field_data_field_state','st','st.entity_id = ta.entity_id');

$sql
    -&gt;fields('ta', array('field_title_value'))        
    -&gt;fields('st',array('field_state_value'));


    $sql-&gt;condition('st.field_state_value', $cond, '=');       



$quer = $sql-&gt;execute();


$rows2 = array();

foreach ($quer as $q){ 

    array_push($rows, array(
        'book_title' =&gt; $q-&gt;field_title_value,
        'book_state' =&gt; $q-&gt;field_state_value,

    ));

}    
$form['table2'] = array(
    '#type' =&gt; 'tableselect',
    '#header' =&gt; $header,
    '#options' =&gt; $rows,
    '#empty' =&gt; t('empty!')
);   
}


Now how can i put result of submit on table1 to show what the query returns ??

Thanks
Digging in, and trying to run some pseudo code it looks like there may be a problem with AJAX callbacks and tableselect fields regarding Drupal Core. 

https://www.drupal.org/node/1458824 (7x and 8x)

I would consider using the Views module with exposed filters.

You could fairly easily create a view that displays 2 articles, which exposes a state drop down list.  You could use a page or block view for the front end.

If you update your question with what you are ultimately trying to accomplish I can try to put together a more appropriate Views setup.