I want to make multiple insert in my database table with a FK, but only enter one line of records, it could be I do not count the $count
. Here my code
Model
public function create($table,$data)
{
$query = $this->db->insert($table, $data);
return $this->db->insert_id();
}
Controller
public function save($id)
{
$id_form = $id;
$id_interversion = $this->model->create('mytable1',$data);
$Inicio = $_POST['Inicio'];
$Termino = $_POST['Termino'];
$id_tecnico = $_POST['id_tecnico'];
$count = count($_POST['id_tecnico']);
$data2 =array();
for ($i=0; $i <$count; $i++) {
$data2 = array(
'id_tecnico'=>$id_tecnico[$i],
'horaInicio'=>$Inicio[$i],
'Termino'=>$Termino[$i]
);
$this->model->create('mytable2',$data2);
}
}
view
<?php echo form_open("controller/save/{$data->id}"); ?>
<?php for ($i=0; $i <2; $i++) { ?>
<input type="text" name="id_tecnico[]" value="" class="form-control">
<input type="text" name="Inicio[]" value="" class="form-control">
<input type="text" name="Termino[]" value="" class="form-control">
<?php } ?>
<?php echo form_close(); ?>
I hope I explained well greetings