Possible Duplicate:
insert multiple rows via a php array into mysql
i am trying to insert only filled data in to the database. my controller
$code=$_POST['code'];
$rate=$_POST['rate'];
$quantity=$_POST['quantity'];
//$total=$_POST['rate']*$_POST['quantity'];
$count = count($_POST['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->load->model('buy_product_model');
$this->buy_product_model->add_product($data);
i have a drop downlist to select shop and for that shop i have created 15 input field.the fields are on the above.the problem is if i only fill up only one or two value it creates 15 rows in the database and 15 time repate the shop name.Can anyone fix this problem.
forloop anywhere, is that just a bad copy and paste from your code - or should I post that as the answer?