Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Builds a select box
- * Function to build and return select box
- * @param string $id
- * @param array $options Structure: Array[i] { [id], [title] }
- * @param int $value
- * @return string html with selectbox
- */
- function inputSelect($id, $options, $value) {
- $strHtml = "<select class=\"form-control\" id=\"" . $id . "\" name=\"" . $id . "\">\n";
- foreach ($options as $option) {
- /* Convert to array with numeric index */
- $array = array_values($option);
- /* Define if option should be selected */
- $selected = ($value === $array[0]) ? "selected" : "";
- /* Accumulate html string with option */
- $strHtml .= "<option value=\"" . $array[0] . "\" " . $selected . ">" . $array[1] . "</option>\n";
- }
- $strHtml .= "</select>\n";
- return $strHtml;
- }
- /* Function Call */
- $strSelect = "SELECT id, name FROM table1 ORDER BY name";
- $arrOptions = $db->fetch_array($strSelect);
- $strOutPut = inputSelect("selectbox_name", $arrOptions, $selected_id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement