Update columns plugin - access row in post eval

PvN94

Member
I have a list with an update column plugin to change a single column. After changing this column I want to insert some of the data from the selected row into another table.
Using the 'Post Eval' field, I wrote some php which should do this using standard placeholders ({tablename___elementname}), only this inserts the literal placeholders into my table. Can I in some way access the id of the updated row in this field and use it to access the data of the updated row?
 
Placeholders are not processed in the post eval code, because that code is run after the individual selected rows have been processed, so there is no single row of data to replace with. In other words, if you selected 10 rows and did an update col, the post eval code has no way of knowing which instance of {tablename___elementname} you want.

However, the row data will be in $data. Iirc it will be grouped, so $data will be an array of arrays, like $data[0]['tablename___elementname']. Even if your list is not set to be grouped, it'll still be an array of one array. So you would process it like ...

Code:
$myDb = JFactory::getDbo();
$myQuery = JFactory::getQuery(true);

// uncomment this to see $data
// var_dump($data);exit;
foreach ($data as $group) {
   foreach ($group as $row) {
      // do your thing with $row data, like ...
     $myQuery
         ->clear()
         ->update('sometable')
         ->set('foo = ' . $myDb->quote($row['tablename___foo']))
         ->where('id = ' . $myDb->quote($row['tablename___bar']));
     $myDb->setQuery($myQuery);
     try {
        $myDb->execute();
     }
     catch (Exception $e) {
       JError::raiseWarning(500, 'oooops!  ' . $e->getMessage());
    }
}

You may need to dump $data and/or $row to see exactly how it is structured.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top