2012-09-25 103 views
0

有點幫助我怎樣才能使用這個數組創建一個輸入查詢?或者如何將 傳遞給表格?我的表佈局示例是這樣的:多維數組Mysql Codeigniter

sales_table

id | product_name | price | qty | subtotal  

這是從的var_dump()函數導出。
這是我在陣列碼

//array code from unserialized function 
    $products = unserialize($this->session->userdata('product_list')); 

//This is the output. 
Array 
(
    [2] => Array 
     (
      [id] => 2 
      [product_name] => NOKIA 5110 
      [product_desc] => Cellphone 
      [product_price] => 500.00 
      [product_qty] => 1 
      [product_amount] => 500 
      [product_code] => NOKI2012-84353 
     ) 

    [3] => Array 
     (
      [id] => 3 
      [product_name] => HP IPAQ RW6828 
      [product_desc] => Cellphone 
      [product_price] => 1500.00 
      [product_qty] => 1 
      [product_amount] => 1500 
      [product_code] => HP I2012-08386 
     ) 
) 
+0

你怎麼得到'product_list'? –

回答

0

請與foreach循環,將遍歷所有的產品,並通過一個

foreach($products as $p) { 
    $data = array(
     'product_name' => $p['product_name'], 
     'price' => $p['product_price'], 
     'qty' => $p['product_qty'], 
     'subtotal' => 1, // what do you want here? 
    ); 

    $data2 = array(
     'product_stuff' => $p['product_code'], 
     'product_stuffo' => 100 * $p['product_amount'], // anything you want 
    ); 


    $this->db->insert('products', $data); 
    $this->db->insert('sales_line', $data2); 
} 

將它們插入一個插入的方法你可能想使這個代碼支持事務處理。

+0

小計在我的會話變量中,我沒有問題。其他的事情是我想存儲在兩個單獨的表另一個是sales_line表 – rochellecanale

+0

@rochellecanale我已經更新了我的答案 –