Answer the question
In order to leave comments, you need to log in
How to split an array of products in order to put these products (one by one) into the database?
There is an array of data, namely a list of goods (naturally, each product is an array of data)!
So here's how to break these products one by one (it's clear how to do it), so that then each of these products can be put into the database (it's not clear) how to put them one by one! Those. the function that takes an array as an argument can write only one product!
Answer the question
In order to leave comments, you need to log in
INSERT INTO table_name (field1, field1, field1, ... , fieldN) VALUES (), (), (), ... , ();
You can insert into the database at each iteration of the loop. In any case, it doesn't matter at all whether goods/not goods, the main thing is to understand the mechanisms.
You can also look at insert on duplicate key update (if mysql, for example). That's right...looking forward to the next question :)
foreach ($elements as $element){
$name=$element[:name];
$detail=$element[:detail];
INSERT INSTO product (name, detail) VALUES ($detail, $detail);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question