1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Get a value from a databasejoin element (other list)

Discussion in 'Community' started by juandress, Feb 21, 2019.

  1. juandress

    juandress New Member

    Level: Community
    Hi , I need to get a value from a previously selected databasejoin element.

    I think about using a calc element to get the value of the other table, but I've looked for a simple way to solve it and it has not worked.

    example
    In form.
    Select Agency (databasejoin element) (list with code agency, name, boss, idboss)

    Calc Element, use php as return {other list} .idboss;

    then, I can use the calc element for pre filter.

    Please , help me
    Thank you in advance.

    Juan
     
  2. troester

    troester Well-Known Member Staff Member

    Level: Community
    Not sure what you mean.
    In a database join element you can select the "Value" (is stored in the database and should be the primary key of your lookup-table, usually id[recommended]) and you can select the "Label" (shown to the user, which can be any column of your lookup-table or a concatenation defined in "or Concat label")
     
  3. juandress

    juandress New Member

    Level: Community
    You are right, I knew it was like that but at the beginning I did not show it well. I tried it and it's fine for what I need.

    Thank you so much
     
  4. juandress

    juandress New Member

    Level: Community
    Hi troester , It may be that when I use a calc element to use a select it does not give me the result because it takes the value of the label and not the field.

    How can I read the field value in the select
    field databasejoin plugin
    {tareas___usuario_asignado} setup
    label = table.agencia, ' | ' , table.name
    value= id


    Ex. calc field
    $id = {tareas___usuario_asignado}; (take the label instead of the value) table.agencia, ' | ' , table.name) resul = Null ----- if I put a constant value 855 the resul is email@email.com
    $db = JFactory::getDbo();
    $query = $db->getQuery(true);
    $query->select('email');
    $query->from($db->quoteName('AGENCIASUSUARIOS'));
    $query->where($db->quoteName('id').' = '.$db->quote($id));

    $db->setQuery($query);
    $email = $db->loadResult();

    return $email;

    How can you read the value of the combobox directly
    When I record the usuario_asignado field it puts the value correctly

    Please , Thank you for your answer

    Juan
     
  5. troester

    troester Well-Known Member Staff Member

    Level: Community
  6. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Also, always quote placeholders in your PHP code, like ...

    Code (Text):

    $id = '{tareas___usuario_asignado_raw}';
     
    If you don't do that, and the element is empty, you'll get a fatal syntaxt error.

    Also, if you are expecting an integer to use as an FK in a query, you can cast it to an int ...

    Code (Text):

    $id =(int) '{tareas___usuario_asignado_raw}';
     
     
  7. juandress

    juandress New Member

    Level: Community
    Excelent!
     

Share This Page