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

PHP read data from dropdown and insert into new database table

Discussion in 'Community' started by dgrimes, Feb 28, 2019.

  1. dgrimes

    dgrimes New Member

    Level: Community
    I have a repeat group that has a dropdown element named "el5ua_bozzuto_inventory_28_repeat___po_item_status", so the element in the form has the ID "el5ua_bozzuto_inventory_28_repeat___po_item_status_0". I am using the PHP Plug-in. I use this line to grab the values from other fields in that group.

    $itemstatus = $data['el5ua_bozzuto_inventory_28_repeat___po_item_status'][0];

    Then I have this line in the insert SQL statement.

    ->set('item_status = ' . $db->quote($itemstatus))

    I get this error.

    SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'field list'

    If I hard code the value everything works fine.

    Can you offer any advice?
     
  2. dgrimes

    dgrimes New Member

    Level: Community
    I see I can use a line like this

    $itemstatus = $data['el5ua_bozzuto_inventory_28_repeat___po_item_status'][0][0];

    I get the value I was looking for; however, what I am really after is the "value" of the "selected" item in the dropdown.

    Any advice?
     
  3. dgrimes

    dgrimes New Member

    Level: Community
    Actually the line above does give me the selected value.

    I hope this helps someone else out there...
     
  4. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Yup. $data['el5ua_bozzuto_inventory_28_repeat___po_item_status'] will be an array because it's in a repeat group, so you have an array of values, one per repeat. Then those values themselves are arrays, because any element which has a concept of multiple value/label (join, dropdown, checkbox, radio, etc) will submit as an array (even if the UI element is a single selection, like single select dropdown).

    Also ... I would recommend doing some sanity checking to make sure those array keys exist, before dereferencing them, to avoid PHP errors / warnings.

    -- hugh
     

Share This Page