I have a temp table created with a list of "master tasks". These need to be duplicated so they can be assigned to users as needed. The problem I have is the table column 'id' is a primary key set to auto increment...how can I update the id column for all rows within the table to something like ++$nid ($nid is the max from another table so I do not have duplicate id's). Here is the code used to update the ID, but it only works when I lock the table, remove the auto increment and drop the primary key..but then the id's are all 206 (first id should be 187 - 206). Any way to update multiple rows where the column is ai and a primary key?
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select(array('id'))
->from('#__temp_tasks');
$db->setQuery($query);
$rows =$db->loadObjectList();
foreach ($rows as $row)
{
// Insert into destination table
$query->clear();
$query->update('#__temp_tasks');
foreach ($row as $rows)
{
$query->set('id' . ' = ' . (int) ++$tasksMaxID);
}
$db->setQuery($query);
$db->execute();
$query->clear();
}