insert php array into mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gamepart
    New Member
    • Oct 2010
    • 1

    insert php array into mysql

    I have an array $product_array, and when I use print_r($produc t_array);. The array shows like this

    Code:
    Array ( 
    
    [0] => Array 
        ( 
           [ID] => P00100 
           [NAME] => Edina 
           [PRICE] => $20.00 )
    
    [1] => Array 
        ( 
            [ID] => P00101 
            [NAME] => Richfield 
            [PRICE] => $21.00 
        ) 
     
    [2] => Array 
        ( 
            [ID] => P00102 
            [NAME] => Bloomington 
            [PRICE] => $22.00 
        )
    I created my database table in 4 columes, first one is mainid, and which is auto increment, following with ID, NAME, PRICE, as the keys showed above. I would like to insert this array $product_array into mysql. Can anyone help? Would be very much appreciated! tks.
    Last edited by Dormilich; Oct 25 '10, 05:45 AM. Reason: please use [CODE] [/CODE] tags when posting code
  • bob2044
    New Member
    • Jun 2009
    • 16

    #2
    Code:
    foreach($prdouct_array as $val){
    	mysql_query("insert into tbl(name,price) values)($val['name'],$val['price']); 
    }
    Last edited by Dormilich; Oct 25 '10, 05:46 AM. Reason: please use [CODE] [/CODE] tags when posting code

    Comment

    Working...