PHP read data from dropdown and insert into new database table

dgrimes

New Member
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?
 
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?
 
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
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top