Add items to database at once

Hi guys,

I am creating some online exercises for my educational website. I have created a quiz, where people can learn some Italian words. Now if an answer is wrong, it is pushed to a table that you can see at the end of the quiz (kind of overview of the things you have to work on). So in most of the cases the table contains several items .


What I want, is that people can create a new exercise with the items of this table. For that I need this items to the database ‘Exercises’. What I have done now (and this doesn’t work):

export function button114_click(event, $w) {
let toInsert = $w("#table1").rows;
wixData.insert("Exercises", toInsert);
}

The table values (columns) are the same as the values of the database. I have read on the page ‘references’ that the ‘Insert’-function can only add one item each time. I am wondering if there is any possibility to add all the items of the table (amount can vary) to the database at once.

Hey
Google or read at w3schools.com about how to make a foreach loop in Javascript.

let toInsert = $w(“#table1”).rows;

  1. Count the records in rows.
  2. Make a loop that will loop through rows items.
  3. Insert into Wix Data Collation.
  4. Loop again from 2

Then it will loop through rows and insert one records per record.

Thanks Andreas, that is all I needed :slight_smile: