Guest User

Untitled

a guest
Jan 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. id | product_name | price | qty | subtotal
  2.  
  3. //array code from unserialized function
  4. $products = unserialize($this->session->userdata('product_list'));
  5.  
  6. //This is the output.
  7. Array
  8. (
  9. [2] => Array
  10. (
  11. [id] => 2
  12. [product_name] => NOKIA 5110
  13. [product_desc] => Cellphone
  14. [product_price] => 500.00
  15. [product_qty] => 1
  16. [product_amount] => 500
  17. [product_code] => NOKI2012-84353
  18. )
  19.  
  20. [3] => Array
  21. (
  22. [id] => 3
  23. [product_name] => HP IPAQ RW6828
  24. [product_desc] => Cellphone
  25. [product_price] => 1500.00
  26. [product_qty] => 1
  27. [product_amount] => 1500
  28. [product_code] => HP I2012-08386
  29. )
  30. )
  31.  
  32. function __construct()
  33. {
  34.  
  35. parent::__construct();
  36. $this->load->model('model_name','',TRUE);
  37. }
  38. function add()
  39. {
  40. //products stuff
  41. $acknowledgement = $this->model_name->add_data($products);
  42. }
  43.  
  44. function add_data($data)
  45. {
  46. foreach($data as $blah)
  47. {
  48. $bar = array(
  49. 'product_name' => $blah['product_name'],
  50. 'price' => $blah['product_price'],
  51. 'qty' => $blah['product_qty'],
  52. 'subtotal' => 5,
  53. );
  54. $this->db->insert('sales_table',$bar)
  55. }
  56. }
  57.  
  58. foreach($products as $p) {
  59. $data = array(
  60. 'product_name' => $p['product_name'],
  61. 'price' => $p['product_price'],
  62. 'qty' => $p['product_qty'],
  63. 'subtotal' => 1, // what do you want here?
  64. );
  65.  
  66. $data2 = array(
  67. 'product_stuff' => $p['product_code'],
  68. 'product_stuffo' => 100 * $p['product_amount'], // anything you want
  69. );
  70.  
  71.  
  72. $this->db->insert('products', $data);
  73. $this->db->insert('sales_line', $data2);
  74. }
Add Comment
Please, Sign In to add comment