Y
Y
yv19952016-04-15 17:06:08
PHP
yv1995, 2016-04-15 17:06:08

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

3 answer(s)
I
Ihor Gevorkyan, 2016-04-15
@yv1995

php loops
php.net/manual/en/control-structures.foreach.php

I
Igor Voronov, 2016-04-15
@ivoronov

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 :)

A
Alexander Petrov, 2016-04-15
@Mirkom63

foreach ($elements as $element){
        $name=$element[:name];
        $detail=$element[:detail];
        INSERT INSTO product (name, detail) VALUES ($detail, $detail);
    }

Something like that. maybe somewhere I accidentally made a mistake in the code, but the idea as a whole is this.
If there are a lot of goods, then I would do the download via ajax so that the server freezes, which will write to the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question