Skip to main content
added 62 characters in body
Source Link
WatsMyName
  • 4.5k
  • 5
  • 49
  • 83

instead of manipulating $_POST in controller manipulate it in model like this

Your controller

$this->load->model('buy_product_model'); $this->buy_product_model->add_product($this->input->post()); 

EDIT

Make sure the form fields in html form are in array form like this

<input type="text" name="code[]" /> 

Your model

public function buy_product_model($postdata){   $code=$postdata['code'];  $rate=$postdata['rate']; $quantity=$postdata['quantity']; //$total=$postdata['rate']*$postdata['quantity'];extract($postdata); $count = count($postdata['code']$code); for($i=0; $i<$count; $i++) { $data = array( 'shop'=>$shop->$this->input->post('shop'), 'code' => $code[$i], 'rate' => $rate[$i], 'quantity' => $quantity[$i], 'total' =>($rate[$i]*$quantity[$i])   );  $this->db->insert('[YOUR TABLE]', $data);  } } 

MAKE SURE TO CHANGE [YOUR TABLE] TO YOURS

add rest of the code you have in method add_product of your model and iterate through a loop as you have done in your controller.

Edit:

Please check 'shop'=>$shop->$this->input->post('shop') part in your loop

instead of manipulating $_POST in controller manipulate it in model like this

Your controller

$this->load->model('buy_product_model'); $this->buy_product_model->add_product($this->input->post()); 

Your model

public function buy_product_model($postdata){   $code=$postdata['code'];  $rate=$postdata['rate']; $quantity=$postdata['quantity']; //$total=$postdata['rate']*$postdata['quantity']; $count = count($postdata['code']); for($i=0; $i<$count; $i++) { $data = array( 'shop'=>$shop->$this->input->post('shop'), 'code' => $code[$i], 'rate' => $rate[$i], 'quantity' => $quantity[$i], 'total' =>($rate[$i]*$quantity[$i]) ); } } 

add rest of the code you have in method add_product of your model and iterate through a loop as you have done in your controller.

Edit:

Please check 'shop'=>$shop->$this->input->post('shop') part in your loop

instead of manipulating $_POST in controller manipulate it in model like this

Your controller

$this->load->model('buy_product_model'); $this->buy_product_model->add_product($this->input->post()); 

EDIT

Make sure the form fields in html form are in array form like this

<input type="text" name="code[]" /> 

Your model

public function buy_product_model($postdata){ extract($postdata); $count = count($code); for($i=0; $i<$count; $i++) { $data = array( 'shop'=>$shop, 'code' => $code[$i], 'rate' => $rate[$i], 'quantity' => $quantity[$i], 'total' =>($rate[$i]*$quantity[$i])   );  $this->db->insert('[YOUR TABLE]', $data);  } } 

MAKE SURE TO CHANGE [YOUR TABLE] TO YOURS

add rest of the code you have in method add_product of your model and iterate through a loop as you have done in your controller.

Edit:

Please check 'shop'=>$shop->$this->input->post('shop') part in your loop

added 90 characters in body
Source Link
WatsMyName
  • 4.5k
  • 5
  • 49
  • 83

instead of manipulating $_POST in controller manipulate it in model like this

Your controller

$this->load->model('buy_product_model'); $this->buy_product_model->add_product($this->input->post()); 

Your model

public function buy_product_model($postdata){ $code=$postdata['code']; $rate=$postdata['rate']; $quantity=$postdata['quantity']; //$total=$postdata['rate']*$postdata['quantity']; $count = count($postdata['code']); for($i=0; $i<$count; $i++) { $data = array( 'shop'=>$shop->$this->input->post('shop'), 'code' => $code[$i], 'rate' => $rate[$i], 'quantity' => $quantity[$i], 'total' =>($rate[$i]*$quantity[$i]) ); } } 

add rest of the code you have in method add_product of your model and iterate through a loop as you have done in your controller.

Edit:

Please check 'shop'=>$shop->$this->input->post('shop') part in your loop

instead of manipulating $_POST in controller manipulate it in model like this

Your controller

$this->load->model('buy_product_model'); $this->buy_product_model->add_product($this->input->post()); 

Your model

public function buy_product_model($postdata){ $code=$postdata['code']; $rate=$postdata['rate']; $quantity=$postdata['quantity']; //$total=$postdata['rate']*$postdata['quantity']; $count = count($postdata['code']); for($i=0; $i<$count; $i++) { $data = array( 'shop'=>$shop->$this->input->post('shop'), 'code' => $code[$i], 'rate' => $rate[$i], 'quantity' => $quantity[$i], 'total' =>($rate[$i]*$quantity[$i]) ); } } 

add rest of the code you have in method add_product of your model and iterate through a loop as you have done in your controller.

instead of manipulating $_POST in controller manipulate it in model like this

Your controller

$this->load->model('buy_product_model'); $this->buy_product_model->add_product($this->input->post()); 

Your model

public function buy_product_model($postdata){ $code=$postdata['code']; $rate=$postdata['rate']; $quantity=$postdata['quantity']; //$total=$postdata['rate']*$postdata['quantity']; $count = count($postdata['code']); for($i=0; $i<$count; $i++) { $data = array( 'shop'=>$shop->$this->input->post('shop'), 'code' => $code[$i], 'rate' => $rate[$i], 'quantity' => $quantity[$i], 'total' =>($rate[$i]*$quantity[$i]) ); } } 

add rest of the code you have in method add_product of your model and iterate through a loop as you have done in your controller.

Edit:

Please check 'shop'=>$shop->$this->input->post('shop') part in your loop

Source Link
WatsMyName
  • 4.5k
  • 5
  • 49
  • 83

instead of manipulating $_POST in controller manipulate it in model like this

Your controller

$this->load->model('buy_product_model'); $this->buy_product_model->add_product($this->input->post()); 

Your model

public function buy_product_model($postdata){ $code=$postdata['code']; $rate=$postdata['rate']; $quantity=$postdata['quantity']; //$total=$postdata['rate']*$postdata['quantity']; $count = count($postdata['code']); for($i=0; $i<$count; $i++) { $data = array( 'shop'=>$shop->$this->input->post('shop'), 'code' => $code[$i], 'rate' => $rate[$i], 'quantity' => $quantity[$i], 'total' =>($rate[$i]*$quantity[$i]) ); } } 

add rest of the code you have in method add_product of your model and iterate through a loop as you have done in your controller.