• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

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