1. NOTICE: If you are using Fabrik and update to Joomla 3.10, you will need to update to Fabrik 3.10. And, if you are using Fabrik, do not upgrade to Joomla 4, we do not have a supported version ready for release. More information on a release date coming soon. Also, please note that Fabrik 3.10 will not install on any Joomla sites less than 3.8.
    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):
    $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}' ");
     
    troester likes this.

Share This Page