Add record on load list

merlino68

Member
I would like to load a list, add a record in a table with the same value as a list field, and with the current user in a table field.

List A
Table A fields :ID_2, user
Add records to table A where ID_2 = Rowid and user = user logged in

Is it possible to do this?

Thank you
 
Use the php_events list plugin, with code in the 'onLoadData' box.

Your list data will be in $model->data, which is an array of arrays (groups) of objects (rows). The row id is in __pk_val.

So to insert a row in another table coresponding to each row in the current list

Code:
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myUserid = JFactory::getUser()->get('id');
// change table and field names to suit
$myQuery->insert($myDb->quoteName('other_table'));
$myQuery->columns($myDb->quoteName(array('ID_2','user')));

foreach ($model->data as $groups) {
   foreach ($groups as $row) {
      $myQuery->values($myDb->quote($row->__pk_val) . ',' . $myDb->quote($myUserid));
   }
}

$myDb->setQuery($myQuery);
$myDb->execute();

-- hugh
 
I have a problem with the plugin
I've successfully installed the plugin but the plugin is not listed in the list plugin list, and not even in the joomla plugin list.
Looking at filezilla in the fabrik plugin folder the folder exists with all the files.
Try copying with filezilla but I still do not see the plugin in the list plugin list:(

Joomla 3.7.2 fabrik 3.6 php 7

Thank you
 
The page is not loaded, the error is this
0 Can not access protected property FabrikFEModelList :: $ data

A clarification, the table is the same as the list ...
Sorry i do not know the php ..

this the code
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myUserid = JFactory::getUser()->get('id');
// change table and field names to suit
$myQuery->insert($myDb->quoteName('tm_schede'));
$myQuery->columns($myDb->quoteName(array('id_allen','id_ins')));

foreach ($model->data as $groups) {
foreach ($groups as $row) {
$myQuery->values($myDb->quote($row->__id) . ',' . $myDb->quote($myUserid));
}
}

$myDb->setQuery($myQuery);
$myDb->execute();
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top