I have a query wherein it fetches data from the database, a simple SELECT
query which is processed when a certain submit button is clicked. What I want to achieve is to get the results of that query so that I can populate it on my form. So far my code looks like this,
function my_module_my_form_submit_go($form, &$form_state){
$values_array = array(
'week' => $form_state['values']['week'],
'employee_name' => $form_state['values']['emp_name'],
);
$result = db_query("SELECT * FROM {time} WHERE week='".$values_array['week']."' AND employee_name='".$values_array['employee_name']."' ");
}
and my form looks like this,
// this is where I want to populate the data which came from the database
$form['week'] = array(
'#type' => 'textfield',
'#title' => 'Week',
'#value' => $result['week'],
);
$form['emp_name'] = array(
'#type' => 'textfield',
'#title' => 'Name',
'#value' => $result['employee_name'],
);
$form['go_btn'] = array(
'#type' => 'submit',
'#title' => t('Go'),
'#value' => 'Go',
'#id' => 'go_btn',
'#submit' => array('my_module_my_form_submit_go'),
);
I am pretty sure that the query has results because I ran it on the database. What I want is to echo/print the results in the form because later on they will be also used in another form submission. How would I do such thing after the submit button is clicked. I have only managed to display a text using drupal_set_message
but any data which came from the database, I can't display any. Please help. Thanks.