1. "Fabrik 4" helpers needed!

    You are invited to join other community members active in coding, maintaining and improving Fabrik. Please visit https://fabrik.help for more information!
    Dismiss Notice

Return checkbox item labels to other list

Discussion in 'Community' started by enrb, Dec 7, 2021.

  1. enrb

    enrb Member

    Level: Community
    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 (Text):
    $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!
  2. juuser

    juuser Well-Known Member

    Level: Community
    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 (Text):
    CASE WHEN color = '1' THEN 'White'
    WHEN color = '2' THEN 'Pink'
    WHEN color = '3' THEN 'Red'
    END AS color
    FROM mytable WHERE id = '{rowid}' ");
    troester likes this.

Share This Page