Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- id | product_name | price | qty | subtotal
- //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
- )
- )
- function __construct()
- {
- parent::__construct();
- $this->load->model('model_name','',TRUE);
- }
- function add()
- {
- //products stuff
- $acknowledgement = $this->model_name->add_data($products);
- }
- function add_data($data)
- {
- foreach($data as $blah)
- {
- $bar = array(
- 'product_name' => $blah['product_name'],
- 'price' => $blah['product_price'],
- 'qty' => $blah['product_qty'],
- 'subtotal' => 5,
- );
- $this->db->insert('sales_table',$bar)
- }
- }
- 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);
- }
Add Comment
Please, Sign In to add comment