Egocentralis
Member
Hi,
In a calc element, what has to load on save I have a query what grabs some details from a table, and if a certain condition is met, inserts the data into another query.
Its almost working, but, when I save the form, the data is inserted 3 times into the database table.
To check what was the output, I tried to put return $gegeven. This is printing one line with the data I need.
Can someone explain what i am missing?
The content of the calc element:
The result of the "Return" Statement on frontend:
As you can see it is one line.
However in the database it looks like this:
On every line exact the same input and content. What I need is to only have inserted one line but probally i do something wrong. Everything else is working, the if statement, the yesno query, the details I load from another table, etc. Except the inserting.
Would be very awesome if someone can tell me the magic.
In a calc element, what has to load on save I have a query what grabs some details from a table, and if a certain condition is met, inserts the data into another query.
Its almost working, but, when I save the form, the data is inserted 3 times into the database table.
To check what was the output, I tried to put return $gegeven. This is printing one line with the data I need.
Can someone explain what i am missing?
The content of the calc element:
Code:
$user = JFactory::getUser();
$user_id = $user->get('id');
$db = FabrikWorker::getDbo();
$qyesno = $db->getQuery(true);
$qyesno
->select("ja_of_nee")
->from("test_hulp_op_afstand")
->where("bedrijf_id IN (SELECT bedrijf_id FROM egocentralis_bedrijven WHERE userid = " . $user_id . ") OR bedrijf_id IN (SELECT bedrijf_id FROM g4e_orakel_personeel WHERE userid = " . $user_id . " ) ");
$db->setQuery($qyesno);
$yesno = $db->loadResult();
$mydb = FabrikWorker::getDbo();
$qgegev = $mydb->getQuery(true);
$qgegev
->select("bedrijf_id, Hulp_naam, Persid_hulp, ww_hulp, mail_hulp, user_id_hulp, Toegang_hulp, afstandhulp, hulpnummer")
->from("hulp_op_afstand")
->where("bedrijf_id IN (SELECT bedrijf_id FROM egocentralis_bedrijven WHERE userid = " . $user_id . ") OR bedrijf_id IN (SELECT bedrijf_id FROM g4e_orakel_personeel WHERE userid = " . $user_id . " ) ");
$mydb->setQuery($qgegev);
$gegevens = $mydb->loadObjectList();
if ($yesno == '1') {
$mydb1 = FabrikWorker::getDbo();
$query_ins_pers = $mydb1->getQuery(true);
foreach ($gegevens as $gegeven) {
$query_ins_pers
->insert('g4e_orakel_personeel')
->columns('date_time, persid, voornamen, achternaam, email, in_dienst_sinds, status, vol_naam, user_group, userid, bedrijf_id')
->values('NOW(), ' . $mydb1->quote($gegeven->Persid_hulp) . ', ' . $mydb1->quote($gegeven->afstandhulp) . ', ' . $mydb1->quote($gegeven->hulpnummer) . ', ' . $mydb1->quote($gegeven->mail_hulp) . ', NOW(), ' . $mydb1->quote('1') . ', ' . $mydb1->quote($gegeven->Hulp_naam) . ', ' . $mydb1->quote($gegeven->Toegang_hulp) . ', ' . $mydb1->quote($gegeven->user_id_hulp) . ', ' . $mydb1->quote($gegeven->bedrijf_id));
$mydb1->setQuery($query_ins_pers);
$mydb1->execute();
return $gegeven;
}} else { return 'testing';}
The result of the "Return" Statement on frontend:
As you can see it is one line.
However in the database it looks like this:
On every line exact the same input and content. What I need is to only have inserted one line but probally i do something wrong. Everything else is working, the if statement, the yesno query, the details I load from another table, etc. Except the inserting.
Would be very awesome if someone can tell me the magic.