Calc element insert query make 3 rows

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:


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:

Screenshot_13.png

As you can see it is one line.

However in the database it looks like this:

Screenshot_14.png

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.
 
The magic is: use more complex php code with form php plugin instead in calc element.
In the begining in my larning fabrik curve a calc element was number one for me.
When i tried php form plugin with separate php file I was born again.
The game started again, but at a faster pace.
 
aha, I understand, and i did not know that. Thats why i am busy with this (in my opinion) easy thing to do...

So, I make the form.. then I activate a php form plugin. And then, i let it fire at "on afterproces"

I think, I can use the same query to achieve that.. or is that to easy thinking?

Well anyway thanks for pointing me out!! I hope I get this ready tonight.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top