I have created a form to allow users to enter some details but I also need to display some mysql data into that form. The contents and fields of the form are displayed in a tabular format. I just want to know the right way to display mysql data in one of the table columns along with the form fields. How can i display select options in selectbox using form-api ?
2 Answers
You can make use of theme_table
to make a table view.
You can use form-api
inside the table as you wish.
Sample code for creating table.
$header = array();
$rows = array();
$rows[] = array(
array('data' => 'Head1', 'rowspan'=> 2, 'header' => 1),
array('data' => 'Head2', 'rowspan'=> 2, 'header' => 1),
array('data' => 'Head3', 'rowspan'=> 2, 'header' => 1),
array('data' => 'Head4', 'rowspan'=> 2, 'header' => 1),
array('data' => 'Head5', 'rowspan'=> 2, 'header' => 1),
array('data' => 'Head6', 'colspan'=> 6, 'header' => 1),
);
$rows[] = array(
array('data' => 'SubHead6-1', 'header' => 1),
array('data' => 'SubHead6-2', 'header' => 1),
array('data' => 'SubHead6-3', 'header' => 1),
array('data' => 'SubHead6-4', 'header' => 1),
array('data' => 'SubHead6-5', 'header' => 1),
array('data' => 'SubHead6-6', 'header' => 1),
);
return $output .= theme('table', $header, $rows);
To make a select box with db values you can try this
$query = "SELECT * FROM {tablemanme}";
$query_result = db_query($query);
while (($data = db_fetch_object($query_result )) !== FALSE) {
$opt[$data->id] = $data->name;
}
$form['select'] = array(
'#type' => 'select',
'#options' => $opt,
);
Good luck.
-
Hi my from fields are displaying in a tabular format but I am not able to display mysql data in the form Commented May 14, 2012 at 5:29
-
@SomyaGupta, What type of mysql data? Do you want to display it inside the form fields?– niksmacCommented May 14, 2012 at 5:35
-
yes I want college names to be displayed as a form field within a table cell So the student can make a selection Commented May 14, 2012 at 5:48
-
You can check on this link
http://public-action.org/content/drupal-7-form-api-drupal-7-multi-step-form-fapi-table-report
It gives you complete idea of displaying data in tabular form
-
-
that's true, but in fact form API in D7 is 95% the same as the one in D6. Commented May 14, 2012 at 6:04