based on insert multiple rows using one forigenk value in form
according to above picture there is dropdown for select project.once select project and user will be able to add other details. now i want to do when form is submitting project_id (id map with project name in drop down)should insert with other rows.
but in my case project_id is inserting with only very first row. below result came when i print the array .
Array ( [0] => Array ( [project_id] => 1 [staff_id] => 2 [item_no] => 1 [description] => 1 [qty] => 1 [unit] => cube [rate] => 1 [laboure_hrs] => 1 [laboure_cost] => 1 [amount] => 2 ) 1 => Array ( [project_id] => [staff_id] => 2 [item_no] => 2 [description] => 2 [qty] => 2 [unit] => sq.ft [rate] => 2 [laboure_hrs] => 2 [laboure_cost] => 2 [amount] => 8 ) [2] => Array ( [project_id] => [staff_id] => 2 [item_no] => 3 [description] => 3 [qty] => 3 [unit] => cube [rate] => 3 [laboure_hrs] => 3 [laboure_cost] => 3 [amount] => 18 ) )
how i can pass project_id for another fields. my code is below
controler
public function create(){
// validate fields
$this->form_validation->set_rules('work_product_id', 'Work Product Id', 'required');
$this->form_validation->set_rules('work_item_description', 'Work Item Description', 'required');
$this->form_validation->set_rules('quantity', 'Quantity', 'required');
$this->form_validation->set_rules('rate', 'Rate', 'required|numeric');
$this->form_validation->set_rules('laboure_hrs', 'Laboure Hrs', 'required|numeric');
$this->form_validation->set_rules('laboure_cost', 'Laboure Cost', 'required|numeric');
if ($_POST)
{
$project_id=$this->input->post('project');
$staff_id=$this->input->post('staff_id');
$item_no=$this->input->post('work_product_id');
$description=$this->input->post('work_item_description');
$qty=$this->input->post('quantity');
$unit=$this->input->post('unit');
$rate=$this->input->post('rate');
$laboure_hrs=$this->input->post('laboure_hrs');
$laboure_cost=$this->input->post('laboure_cost');
$amount=$this->input->post('txtmultTotal');
$data= [];
for ($i = 0; $i < count($this->input->post('work_product_id')); $i++)
{
$data[$i] = array(
'project_id' => $project_id
'staff_id' => $staff_id[$i],
'item_no' => $item_no[$i],
'description' => $description[$i],
'qty' => $qty[$i],
'unit' => $unit[$i],
'rate' => $rate[$i],
'laboure_hrs' => $laboure_hrs[$i],
'laboure_cost' => $laboure_cost[$i],
'amount' => $amount[$i],
);
}
print_r($data);
$this->boq_model->create($data);
}
}
model
function create($data){
$this->db->insert_batch('boq',$data);
}