PHP to insert multiselect dbjoin into table

jh

Member
Hi

Ive been trying to work out how to insert the value of a multiselect drop down dbjoin element from one table into another table via php. Using the php form plugin, I am currently able to insert the values (into a standard field element) along the lines of:

->set('associate = ' . $db->quote('{designer_table___styles_test_raw}'))

which returns the key values (eg 4,6,9) but I guess it needs to be returned in the right format (something like ["4","6","9"] so it can be used as a dbjoin field (it currently only shows the first value when the field is changed to a dbjoin).

I tried to decode the data first but it still just returns the values as a list of numbers.

Any help would be great.

Kind Regards
 
A multiselect dbjoin uses a link table `your-table_repeat_your-dbjoin-element`
with columns `parent_id` (your record id) and `your-dbjoin-element` (holding the value of your dbjoin lookup table)
 
Hi

Thank you for your response.

My repeat table is 'designer_table_repeat_styles_test' and the element 'styles_test'.

I have tried this:

$dbx = $formModel->getElementData('designer_table_repeat_styles_test___styles_test');

however nothing gets returned.

Please could you kindly advise what I need to do to get this to work?

Many thanks.
 
I don't understand what you are trying to do, I only described where you'll find the multi-select dbjoin in the database.
 
Hi

Thank you for your reply.
I am trying to use a php form plugin to create a copy of submitted data on to another table.
I am able to get the data from all elements apart from where the data on the original form/table is stored as a multiselect dbjoin dropdown.
I have tried to get this data like this: ('designer_table_repeat_styles_test___styles_test' is the repeat group multiselect dbjoin)


$db = JFactory::getDbo();
$userid = JFactory::getuser()->get('id');
$dbx = $formModel->getElementData('designer_table_repeat_styles_test___styles_test');
$query = $db->getQuery(true);
$query->insert('user_edits_testing')
->set('date_time = NOW()')
->set('user_id = ' . $db->quote($userid))
->set('designer_name = ' . $db->quote('{designer_table___designer_name}'))
->set('description = ' . $db->quote('{designer_table___notes}'))
->set('associate = ' . $db->quote($dbx));
$db->setQuery($query);
$db->execute();
$id = $db->insertid();


but there is nothing returned in 'assocate' in the second table. What else do I need to do?

Thank you for any help.
 
PHP:
$ids = $data['table_name___el_name_raw'];
echo '<pre>array:<br>' . var_export($ids, true) . '</pre>';
exit;
 
Hi

Thank you for your response.
Using

$data['table_name___el_name'];

I can now get the element values showing in the new table. However I cannot use:

$data['table_name___el_name_raw'];

as on submit it returns:

"Unknown column 'Array' in 'field list'"

My working code looks like this:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$idx = $data['designer_table___styles_test'];
$query->insert('user_edits_testing')
->set('date_time = NOW()')
->set('parent_id = ' . $db->quote('{designer_table___id}'))
->set('associate = ' . $db->quote($idx));
$db->setQuery($query);
$db->execute();
$id = $db->insertid();

How can I get 'designer_table___styles_test_raw' into my new table?

Many thanks.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top