Forums

Saving multiple records in 1 table

wwgg 13 Feb, 2017
On my site: http://gemertzingt.nl/index.php/inschrijven there is a signup form.

People signup with a team name and a team captain and some extra fields.
After that they add contestants to their team..

A DB Save only saves the team name and captains information..
I want all contestants to be in the table as well.. No need for a separate tabel. Just one table will do

TeamName | TeamCaptain | CaptainMail | CaptainPhone | Remarks | Contestant Name
Team 1 | captain 1 | mail1@mail.nl | 0987654321 | noremarkhs | Contestant 1
Team 1 | captain 1 | mail1@mail.nl | 0987654321 | noremarkhs | Contestant 2
Team 1 | captain 1 | mail1@mail.nl | 0987654321 | noremarkhs | Contestant 3
Team 1 | captain 1 | mail1@mail.nl | 0987654321 | noremarkhs | Contestant 4
Team 2 | captain 2 | mail2@mail.nl | 3456788765 | noremarkhs | Contestant 1
Team 2 | captain 2 | mail2@mail.nl | 3456788765 | noremarkhs | Contestant 2
Team 2 | captain 2 | mail2@mail.nl | 3456788765 | noremarkhs | Contestant 3
etc etc

I have been struggling for a couple of days now, and cannot get my head around it.
Please help.
GreyHead 13 Feb, 2017
Hi wwgg ,

You can do this with one table but it will take more work.

You'd have to use a Custom Code action to loop through the $form->data['Naam'] entries and add all the other data to them, then use a DB Save with the Multi Save setting enabled to save all the records.

Better to save the basic data to table 1, then add the new record ID to the $form->data['Naam'] entries and save those in a second table.

Adding a Debugger to your form on Submit event will let you see the data you have to save.

Bob
wwgg 14 Feb, 2017
Can you give me a hint on the loop through ??


The guy I make this site for needs ONE excell file with the data.
Do for me personally it is easier to provide one tabel.


I really don't know where to start


My array:

    [chronoform] => Inschrijven-mei-2017
    [event] => submit
    [team] => Test Team 123
    [captain] => 123
    [captainmail] => 123@123.ll
    [captainphone] => 123
    [opmerking] => 123 test
    [nix18] => 1
    [Naam] => Array
        (
            [0] => Array
                (
                    [data] => SDeelenemr 12
                )

            [1] => Array
                (
                    [data] => Deelenemr 345
                )

        )

    [button5] => Schrijf in!
Max_admin 15 Feb, 2017
1 Likes
Hi wwgg,

in a custom code action before the db save:

<?php
$form->data["rows"] = array();
foreach($form->data["Naam"] as $k => $name){
$form->data["rows"][$k]["contestant"] = $name;
$form->data["rows"][$k]["captainphone"] = $form->data["captainphone"];
//other fields
}


Then in the db save, choose to save multiple records, and the data path is "rows".

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.