Forums

Dynamic Dropdown: key and value from two different tables

M.Abletech 10 Jul, 2018
Hi,

I wish I can create a Dropdown which has as key data from a READ DATA e value from one another.

Is that possible?

Thanks!
healyhatman 11 Jul, 2018
Sure is! Add a second model in the read data action for your other table. Then the first one should still return key/value pairs and you will be retrieving

model1.field
model2.field
healyhatman 11 Jul, 2018
1 Likes
Sure is! Add a second model in the read data action for your other table. Then the first one should still return key/value pairs and you will be retrieving

model1.field
model2.field
M.Abletech 11 Jul, 2018
thanks Healyhatman!

In the end I prefered using Php action.
I have two dropdowns: the second one uses the following action to retrieve an array key='id' , value='name' :

---------------------------------------------------------------------------------------------------
​$opzioni = [];

// Get a db connection.
$db = JFactory::getDbo();

// Create a new query object.
$query = $db->getQuery(true);

// Select records
$query->select($db->quoteName(array('id', 'name')));
$query->from($db->quoteName('#__fields_values', 'v'));
$query->join('INNER', $db->quoteName('#__kizgv_users', 'u') . ' ON (' . $db->quoteName('u.id') . ' = ' . $db->quoteName('v.item_id') . ')');
$query->where($db->quoteName('value') . ' = '. $db->quote($form->data['select1']));

// Reset the query using our newly populated query object.
$db->setQuery($query);

// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$opzioni = $db->loadAssocList('id','name');

return $opzioni;

------------------------------------------------------------------------------------------------

Thou, it is not loading the dropdown.

Can you kindly spot any issue?

Thanks!!
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger