Using php List plugin to insert row in another table

uktran

Member
{i just subscribed but couldn't post so I'm posting here for now}

Hi, I have a list called 1 with two fields. 1_fieldA, 1_fieldB
and a list called 2 with three fields 2_fieldA, 2_fieldB, 2_fieldC

I would like to have a php button on list 1, so when clicked, a new row is inserted into list 2, with the A and B field data copied across.

I've spend a couple of days trying to do this from the docs, I've managed to work out how to copy IDs and row numbers from the docs, but I can't figure out how to copy across element data into the new row in the other table
 
Hmmm. Did you try logging out of the J! side of the site as well?

Everything looks good from this end. If you have tried logging out form J!, let me know, there's something else I can try.

-- hugh
 
no worries!

I don't mind keeping the community hat - if I get a solution to this problem for 20 bucks I'm happy with that :)
 
Not so good to start list names with a number, this can cause issues.

http://fabrikar.com/forums/index.php?wiki/php-list-plugin/#sample-code
http://fabrikar.com/forums/index.php?wiki/common-php-tasks/#insert

So something like
Code:
...
foreach ($ids AS $myid)
{
    $row = $model->getRow($myid);
    $elementA = $row->your-full-elementnameA;
    $elementB = $row->your-full-elementnameB;
...
// Get a db connection.
$db = JFactory::getDbo();
 
// Create a new query object.
$query = $db->getQuery(true);
 
// Insert columns.
$columns = array('fieldA', 'FieldB');
 
// Insert values.
$values = array($elementA, $elementB);
 
// Prepare the insert query.
$query
    ->insert($db->quoteName('tablename'))
    ->columns($db->quoteName($columns))
    ->values(implode(',', $db->quote($values)));
 
// Reset the query using our newly populated query object.
$db->setQuery($query);
...
}
 
the database is unaffected by this code. I've put in my changes as follows

foreach ($ids AS $myid)
{
$row = $model->getRow($myid);
$elementA = $row->mytable___file;
$elementB = $row->mytable___email;

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

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

// Insert columns.
$columns = array('File', 'Email');

// Insert values.
$values = array($elementA, $elementB);

// Prepare the insert query.
$query
->insert($db->quoteName('mytable'))
->columns($db->quoteName($columns))
->values(implode(',', $db->quote($values)));

}
 
My code is only an example for how to combine the sample code of the both WIKI links I gave you (did you recognize the ...?)

You have to fetch the selected ids and you have to execute the query.
 
We are in need of some funding.
More details.

Thank you.
Back
Top