UPSERT REPEATABLE VALUES

acardoso23

New Member
Hi

I have been trying to insert values in a different table from a repeatable group, but I can only add when it?s a single row. How can I upsert values when it?s more than one row?

Thanks
 
I have solved this question so whoever needs the solution, here you have it:

$db = JFactory::getDbo();
$ids = JRequest::getVar('ids', array());
$app = JFactory::getApplication();
$sql = "SELECT element FROM table INNER JOIN 2nd table ON element == 2ndtable element";
$db->setQuery($sql);
$query = mysqli_query($sql);
$part=explode(",",'{table___element}');
foreach( $part as $value)
{

$insert = "INSERT INTO `2ndtable` (`element` ) VALUE ('".$value."') ";
$db->setQuery($insert);
$db->query();
}
 
That code doesn't look healthy. JRequest has been deprecated since about 2013, and you don't appear to be using the 'ids', and you shouldn't be using mysqli_query, you should be using $db->execute().

Where are you running this? In a form submission plugin, or a list plugin?

-- hugh
 
It looks like that code was based on a list PHP plugin example from a loooong time ago.

One immediate concern would be that you are going to be inserting new rows in the second table every time you submit, like when editing as well as creating a new form, rather than "upserting" (inserting if it's a new form, updating if it's editing an existing form).

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

Thank you.

Members online

Back
Top