problem: only saves the last record in the database

only save the last record from an array to the database.

Overview

The issue occurs because the data source for the save function contains both individual fields and an array of records, causing only the top-level fields to be processed.
Reformat the data source to correctly structure the array of records so that the save function iterates through and saves each item individually.

Answered
ChronoForms v6
Fr Fredolino 14 Oct, 2020
Hello,

i want to save data to the database and i have a save_data function.
The data is displayed in the debugger under "save_data_species".
But it only saves the last record in the database for me.
Can someone tell me where the problem is?

regards
F.
[save_data_species] => Array
        (
            [data] => Array
                (
                    [0] => Array
                        (
                            [MTB_Art] => Array
                                (
                                    [beo_art_id] => 2319
                                    [count_species] => 1
                                    [beof_id] => 1262
                                )

                            [MTB_Fundort] => Array
                                (
                                    [mtb_id] => 2752
                                )

                        )

                    [1] => Array
                        (
                            [MTB_Art] => Array
                                (
                                    [beo_art_id] => 1947
                                    [count_species] => 4
                                    [beof_id] => 1230
                                )

                            [MTB_Fundort] => Array
                                (
                                    [mtb_id] => 3245
                                )

                        )

                    [2] => Array
                        (
                            [MTB_Art] => Array
                                (
                                    [beo_art_id] => 2321
                                    [count_species] => 1
                                    [beof_id] => 1265
                                )

                            [MTB_Fundort] => Array
                                (
                                    [mtb_id] => 3246
                                )

                        )

                    [3] => Array
                        (
                            [MTB_Art] => Array
                                (
                                    [beo_art_id] => 1955
                                    [count_species] => 1
                                    [beof_id] => 1238
                                )

                            [MTB_Fundort] => Array
                                (
                                    [mtb_id] => 5243
                                )

                        )

                    [TKnr] => 5243
                    [Species] => 1
                )

            [_success] => Data saved successfully
            [log] => Array
                (
                    [0] => INSERT INTO `mtb_map_germany` (`TKnr`, `Species`)  values  ('5243', '1') ON DUPLICATE KEY UPDATE `TKnr` = '5243',`Species` = '1';
                )

            [var] => Array
                (
                    [TKnr] => 5243
                    [Species] => 1
                    [id] => 
                )

        )

)
Max_admin Max_admin 23 Oct, 2020
Answer
The data source for the "Save data" is not formatted correctly, you have TKnr and Species fields, then you have an array of arrays, so it saves the fields and ignores the arrays, what do you expect to save exactly ?
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.