Database Reference
In-Depth Information
20.3. Creating Multiple-Pick Form Elements from
Database Content
Problem
A form must present a field that offers several options and enables the user to select any
number of them.
Solution
Use a multiple-pick list element, such as a set of checkboxes or a scrolling list.
Discussion
Multiple-pick form elements enable you to present multiple choices, any number of
which can be selected, or possibly even none of them. For our example scenario in which
customers order cow figurines online, the multiple-pick element is represented by the
set of accessory items that are available. The accessory column in the cow_order table
is represented as a SET , so the following statement returns the permitted and default
values:
mysql> SELECT COLUMN_TYPE, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS
-> WHERE TABLE_SCHEMA='cookbook' AND TABLE_NAME='cow_order'
-> AND COLUMN_NAME='accessories';
+---------------------------------------------------+----------------+
| COLUMN_TYPE | COLUMN_DEFAULT |
+---------------------------------------------------+----------------+
| set('cow bell','horns','nose ring','tail ribbon') | cow bell,horns |
+---------------------------------------------------+----------------+
The values listed in the definition can be reasonably represented as a set of checkboxes
or a multiple-pick scrolling list. Either way, the cow bell and horns items should be
selected initially because each is present in the column's default value. The following
discussion shows the HTML syntax for these elements, then describes how to generate
them from within scripts.
The material in this section relies heavily on Recipe 20.2 , which dis‐
cusses radio buttons, pop-up menus, and single-pick scrolling lists. I
assume that you've already read that section.
Checkboxes
A group of checkboxes is similar to a group of radio buttons in that it consists of
<input> elements that all have the same name attribute. However, the type attribute
is checkbox rather than radio , and you can specify checked for as many items in
Search WWH ::




Custom Search