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?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183

2 Answers2

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);
}
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
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.

DmiN
  • 736
  • 1
  • 7
  • 21