0
Good afternoon, you guys. First forgive me if it’s a very ridiculous question, I’m learning to tinker with the language still. I have the following json:
[
{
"id": 0,
"codigo": "847010",
"valorTotal": 3652.44,
"qtdTotal": 20,
"descricao": "Lorem ipsum dolor sit amet,",
"produtos": [
{
"id": 0,
"nome": "Produto1",
"preco": 100,
"quantidade": 50,
"totalParcial": 1826.22
},
{
"id": 1,
"preco": 100,
"quantidade": 50,
"totalParcial": 1826.22
}
]
},
{
"id": 1,
"codigo": "010410",
"valorTotal": 408.84000000000003,
"qtdTotal": 6,
"descricao": "Lorem ipsum dolor sit amet,",
"produtos": [
{
"id": 2,
"preco": 10,
"quantidade": 2,
"totalParcial": 136.28
},
{
"id": 3,
"preco": 10,
"quantidade": 2,
"totalParcial": 136.28
},
{
"id": 4,
"preco": 10,
"quantidade": 2,
"totalParcial": 136.28
}
]
}
I would like to know how to go through this array and insert it into mysql with php, I am using json_decode to transform JSON into array and doing a foreach to traverse it-Ló, I would need the products to be inserted with the code that precedes them, Each product is a ROW in the products table. Could someone give me an example, a light, please, I’m banging my head with this.
It seems to be on the right track - or at least functional. Inside the loop foreach you can run the SQL that inserts the data into the database. What data set is using?
– Woss