2012-09-25 2 views
0

이 배열을 사용하여 어떻게 입력 쿼리를 만들 수 있습니까? 아니면 을 테이블에 전달할 수 있습니까? 이것은 위해서 var_dump() 함수에서 파생Multidimensional Array to Mysql Codeigniter

id | product_name | price | qty | subtotal  

sales_table

: 내 테이블 레이아웃 샘플이 있습니다.
여기

//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($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); 
} 

에 의해 그들에게 하나를 삽입하는 foreach 루프에 삽입하는 방법을 확인 배열 내 코드입니다 코드는 나중에 트랜잭션을 지원합니다.

+0

소계가 내 세션 변수에 있습니다. 문제가 없습니다. 다른 것은 내가 별도의 두 테이블에 저장하고 싶습니다. 다른 하나는 sales_line 테이블입니다. – rochellecanale

+0

@rochellecanale 제 답변을 업데이트했습니다. –