1
I need to record several records at once in Mysql for example.
I own the tables PRODUTOS
, CATEGORIAS
and a third table that lists the two and also a form where I select the category and mark all the checkboxes of the products that will be inserted in this category, I need each checkbox marked to become a record in the table so I can have 'N' records at the same time.
The record in the third table would look like this:
ID: 1 | Categoria: 1 | Produto: 1
ID: 2 | Categoria: 1 | Produto: 2
ID: 3 | Categoria: 1 | Produto: 3
ID: 4 | Categoria: 1 | Produto: 4
Each product entered was a checkbox marked and the product is related to category 1 (1 = category ID)
What I want is exactly this, to insert several data into a single table, because the first two are already filled with the proper records, what I wish to know is what I must do to perform this insertion of multiple records because Inserts will not always have the same amount of records, may be that in a first insert I relate 2 products to a category after I relate 5 products to another category, so I wonder if I have to make a loop or something similar so that the Insert knows how many records will be entered.
– Dark Media
If I understand correctly, then no. You don’t need to make any loop when inserting the new values. Regarding the fact of relating different products in different categories, it does not interfere in anything in the query. You can do all this in the same query. Just you adjust your code for this.
– bcfurtado
But this is exactly what I’m not knowing, what is the logic to insert multiple data at the same time in the table in a single Insert.
– Dark Media