Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question
1  
What have you tried? We're not here to create code for you. ^^ – Jon Mar 17 at 11:21

marked as duplicate by George Reith, hjpotter92, NikiC, Mathieu Imbert, Craig Swing Mar 17 at 13:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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);
}
share|improve this answer

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.