I want to insert script using CodeIgniter two table table1 and table2.
table1 insert one time date but table2 three times date using for loop but getting an error. Loop is not working, kindly provide some suggestions.
Thanks
Code:
public function add_rdi() {
$user_id = $this -> input -> post('user_id');
$user_rdi = $this -> input -> post('user_rdi');
$zoneID = $this -> input -> post('zoneID');
$mtstock6 = $this -> input -> post('mtstock6');
$tfstank6 = $this -> input -> post('tfstank6');
$data = [
'user_id' => $user_id,
'user_rdi' => $user_rdi,
'zoneID' => $zoneID,
'mtstock6' => $mtstock6,
'tfstank6' => $tfstank6,
];
$data1 = ['fuelstock' => $gtfb,
'fuelrecrdi' => $gtfb,
'stockrdiname' => $user_rdi,
'vfstock' => $tfstank1,
'vfstock' => $tfstank2,
'vfstock' => $tfstank3,
'hfstock' => $tfstank4,
'hfstock' => $tfstank5,
'hfstock' => $tfstank6,
'user_id' => $user_id
];
$this -> load -> model('Mechanical_model_rdi');
$query = $this -> db -> where('rdiname', $rdiname);
$query = $this -> db -> get('fuel_rdi');
if ($query -> num_rows() < 1) {
$this -> Mechanical_model_rdi -> add_rdi($data);
for ($i = 1; $i <= 3; $i++) {
$this -> Mechanical_model_rdi -> add_rdi($data1);
}
} $this -> load -> view('mechanical/Mechanical_add_rdi');
}