I need a query for a form, to get the stored value of a radiobox / dropdown-field (single-select) of CB in the mysql data base.
That can be used in RS!Forms Pro to edit only a special set of profile data beside the CB profile edit.
I know:
1) the chosen data are stored per User in xxxx_comprofiler
2) the fields are stored in xxxx_comprofiler_fields
3) the value/label pairs are stored in xxxx_comprofiler_field_values
My base for an query is:
Code:
$db->setQuery("SELECT 'Field1` FROM `XXXX_comprofiler` WHERE `user_id`='".$userId."'");
By this I only get the stored value.
But the form needs also the value|label pairs, which are stored at 3)
The sample code for the form (RS!Forms Pro) is:
Code:
//<code>
// Prepare the empty array
$items = array();
// Prepare the database connection
$db = JFactory::getDbo();
// Keep this if you'd like a "Please select" option, otherwise comment or remove it
$items[] = "|Please Select[c]";
// Run the SQL query and store it in $results
$db->setQuery("SELECT your_value, your_label FROM #__your_table");
$results = $db->loadObjectList();
// Now, we need to convert the results into a readable RSForm! Pro format.
// The Items field will accept values in this format:
// value-to-be-stored|value-to-be-shown
// Eg. m|M-sized T-shirt
foreach ($results as $result) {
$value = $result->your_value;
$label = $result->your_label;
$items[] = $value.'|'.$label;
}
// Multiple values are separated by new lines, so we need to do this now
$items = implode("\n", $items);
// Now we need to return the value to the field
return $items;
//</code>
Link to RS!Joomla
So the query must contain a subquery, to fill in the possible value|label pairs and show the right value|label pair by the stored value.
Do you have a hint for usage the above code with the CB fields?
Thanks a lot!