IDBSelect
From FiFormsWiki
iDBSelect creates a data bound selection box. The rows in the drop-down box are loaded from an SQL query, and the selected item is stored as a value in a field.
Contents |
XML iDBSelect
The iText element and attributes are documented at http://xml.fiforms.org/schema/11/doc/FiForm.html#element_iDBSelect
The following example is a typical representation of a data bound iDBSelect in an XML form definition:
<iDBSelect
caption="State"
field="STATE_ABBREVIATION"
rowQuery="SELECT STATE_ABBREVIATION, STATE_NAME FROM states" />
In this example, the states table contains a list of state abbreviations and state names. We want to store the state abbreviation in the table this form is bound to, but we want the user to see the full state name. Since two columns are returned from rowQuery, the first column is used as the key column, and the second column contains the value displayed to the user. If there is only one column returned from the query, it is used as both the key and the display column.
PHP Implementation Details
The following information describes the internal PHP Implementation of the iDBSelect element. This information may be somewhat outdated--the best source of implementation details is the actual source code.
Properties
class iDBSelect extends iInput
| $radioStyle | If true, outputs radio buttons instead of a select box. |
| $rowQuery | SQL query used to fill the the select box. This query should return exactly 1 or 2 columns. If 2 columns, the first is values stored in the field and the second is the values displayed in the dropdown box. This can also be an array of values or a 2-dimensional array of containting key/value pairs instead of an SQL statement. |
Properties inherited from iInput: $caption $currentRec $dbField $error $errorMsg $formatStr $formatStrRO $otherTags $readOnly $section $value $valueToSave
Method Detail
Methods inherited from iInput
- checkRO
- drawInput
- getValueToSave
- hide
- iInput
- throwError
iDBSelect
Constructs a new iDBSelect.
Syntax: iDBSelect($dbField,$caption,$rowQuery,$radioStyle)
Parameters
$dbField - Bound database field, containing value or key in select box.
$caption - Field caption
$rowQuery - Either an SQL statement returning values or key/value pairs, OR an array of values or an array of 2-element arrays (key/value pairs).
$radioStyle - (optional) if TRUE, output radio buttons instead of a select box.
Examples
Example
Select box bound to SQL query returning 2 values
$frm->inputs[] = new iDBSelect(
"ST",
"State",
"SELECT ST_ID, ST_ABBR FROM STATES"
);
Example
Select box bound filled with single array of values
$frm->inputs[] = new iDBSelect(
"PER_STATUS",
"Marital Status",
array("Single","Married","Separated","Divorced","Other")
);
Example
Select box with array of name/value pairs
$frm->inputs[] = new iDBSelect(
"PER_STATUS",
"Marital Status",
array(array(1,"Single"),
array(2,"Married"),
array(3,"Separated"),
array(4,"Divorced"),
array(5,"Other")
),
TRUE
);
Returns
A new iDBSelect object
