Actions

J1.5

Difference between revisions of "SQLMultiSelectX"

From Joomla! Documentation

m (See also: - made a second level heading)
(Fix red links)
 
Line 3: Line 3:
 
===Functionality===
 
===Functionality===
 
The SQLMultiListX element will create a list box which consists of the user specified options and the results from an SQL query. In addition to this, it will be possible for the users to select multiple items of the list box and save the preferences.
 
The SQLMultiListX element will create a list box which consists of the user specified options and the results from an SQL query. In addition to this, it will be possible for the users to select multiple items of the list box and save the preferences.
Therefore, SQLMultiListX can be viewed as a hybrid of [[List parameter type]], [[Sql parameter type]] and [[Adding_a_multiple_item_select_list_parameter_type|Multiple Select List parameter type]].
+
Therefore, SQLMultiListX can be viewed as a hybrid of [[J1.5:List parameter type|List parameter type]], [[J1.5:Sql parameter type|Sql parameter type]] and [[Adding_a_multiple_item_select_list_parameter_type|Multiple Select List parameter type]].
 
The options that are specified by the user explicitly via the <option> tags will be rendered first followed with the result of the SQL query. It is up to the developer to ensure that the explicitly specified options do not have ''values'' that conflict with the SQL result.
 
The options that are specified by the user explicitly via the <option> tags will be rendered first followed with the result of the SQL query. It is up to the developer to ensure that the explicitly specified options do not have ''values'' that conflict with the SQL result.
 
==Rendering the parameter==
 
==Rendering the parameter==
Line 56: Line 56:
 
                 // Query items for list.
 
                 // Query items for list.
 
$db = & JFactory::getDBO();
 
$db = & JFactory::getDBO();
$db->setQuery($node->attributes('query'));
+
$db->setQuery($node->attributes('sql'));
 
$key = ($node->attributes('key_field') ? $node->attributes('key_field') : 'value');
 
$key = ($node->attributes('key_field') ? $node->attributes('key_field') : 'value');
 
$val = ($node->attributes('value_field') ? $node->attributes('value_field') : $name);
 
$val = ($node->attributes('value_field') ? $node->attributes('value_field') : $name);
Line 90: Line 90:
 
<source lang="xml">
 
<source lang="xml">
 
<param name="field-name" type="sqlmultilistx" sql="SELECT * FROM #__jos_mytable" key_field="id" value_field="name" default="OPT1"
 
<param name="field-name" type="sqlmultilistx" sql="SELECT * FROM #__jos_mytable" key_field="id" value_field="name" default="OPT1"
multiple="multiple" label="Select one or more items" description="description="Use Ctrl-click to select more than one item.">
+
multiple="multiple" label="Select one or more items" description="Use Ctrl-click to select more than one item.">
 
<option value="-2">Title for option 1</option>
 
<option value="-2">Title for option 1</option>
 
<option value="-1">Title for option 2</option>
 
<option value="-1">Title for option 2</option>
Line 130: Line 130:
 
==Saving parameter values to a database==
 
==Saving parameter values to a database==
 
The most common use for this custom parameter type will involve saving whatever values the user selected into a field in
 
The most common use for this custom parameter type will involve saving whatever values the user selected into a field in
a database table.  Assuming you are doing this using the [[JTable]] API class, then you will need to add the following code
+
a database table.  Assuming you are doing this using the [[API15:JTable|JTable]] API class, then you will need to add the following code
to the [[JTable]] extended class for the appropriate table.
+
to the [[API15:JTable|JTable]] extended class for the appropriate table.
 
<source lang="php">
 
<source lang="php">
 
     /**
 
     /**

Latest revision as of 02:06, 3 July 2013