Return checkbox item labels to other list

enrb

Member
Good morning,
in a list I have an element that I called COLOR of type checkbox (where the values are 1, 2, 3, ... while the labels are: white, pink, red, ...)

In another list I wanted to create an element that would give me the labels (white, pink, red) if the id of the first list and the second list matched.
I have tried with a query inserted in a calc element, but I can only see the values (1, 2, 3) and not the labels.

The query I use is this:

Code:
$mydb = JFactory::getDBO();
$mydb->setQuery(" SELECT mytable.color FROM mytable WHERE mytable.id = '{rowid}' ");
$rows = $mydb->loadObjectList();

$myhtml = "";
foreach ($rows as $row) {
   $myhtml .= $row->color." ";
}
return $myhtml;


Is it possible to view the labels?

Thanks a lot to everyone!
 
When you check the database, you can see that checkbox element values are stored as ["1"] etc. Labels are in Fabrik element database table somewhere in a params json string.

Here are a few options:

1) Have a separate list for colors where you have the id and color name (label) field. And then in your other list, use databasejoin element referring to Colors list and rendered as checkbox. In that case you can select the "label" element from your Colors table instead of id.

2) Use color name also for value in your checkbox element (e.g. value and label both "white").

3) If you have just a few colors and they are pretty static, you can use "CASE" in your query, like:
Code:
$mydb->setQuery("SELECT
CASE WHEN color = '1' THEN 'White'
WHEN color = '2' THEN 'Pink'
WHEN color = '3' THEN 'Red'
END AS color
FROM mytable WHERE id = '{rowid}' ");
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top