0

I have an array in php like this

array (
  0 => 
  array (
    'idprodotto' => '1',
    'prodotto' => 'Banana',
    'cordinaten' => '42.75495',
    'cordinatee' => '13.9365',
  ),
  1 => 
  array (
    'idprodotto' => '2',
    'prodotto' => 'Pera',
    'cordinaten' => '42.74159',
    'cordinatee' => '13.88792',
  ),
  2 => 
  array (
    'idprodotto' => '3',
    'prodotto' => 'Mela',
    'cordinaten' => '42.65719',
    'cordinatee' => '13.89273',
  ),
)

How insert in db ? i have field idprodotto prodotto cordinaten cordinatee but how insert?

0

2 Answers 2

0

You can use SafeMysql library for this.

Assuming you have a connection already established, all the code you need is

foreach ($array_with_data as $row)
    $db->query("INSERT INTO table SET ?u",$row);
}
Sign up to request clarification or add additional context in comments.

Comments

0

The native way is to set on a for-each-loop, then iterate through the array and iterate through it and execute a query that inserts a single-line into a table for each field in the array.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.