If I have a function like this:
public function access_1()
{
$this->db->set('Name', $name);
$this->db->set('Description', $desc);
$this->db->insert('access_user');
$id_access_1 = $this->db->insert_id();
return (isset($id_access_1)) ? _________ : FALSE;
}
In return (isset($id_access_1))
then in the blank (_____) it will process the second function and set the $id_access_1
in that function.
Like this:
public function access_2()
{
$this->db->set('Access_1_ID', ____________);
$this->db->set('Dept', $dept);
$this->db->set('Section', $section);
$this->db->insert('access_dept');
$id_access2 = $this->db->insert_id();
return (isset($id_access2)) ? $id_access2 : FALSE;
}
Below is the controller, the function access_2()
is inside for each()
, like this one:
$this->form_validation->set_rules('name', 'Name', 'required|xss_clean');
$this->form_validation->set_rules('desc', 'Description', 'required|xss_clean');
if ($this->form_validation->run() == true)
{
$this->structure_management->insert_batch($data);
$data = $this->input->post('data');
$access_2Data = json_decode($data,TRUE);
foreach ($access_2Data as $getAll)
{
$this->structure_management->access_2($getAll);
}
else{
}
In the program I have right now, when I click SUBMIT button it will process the two functions but then I figure out how will I get the ID of function access_1()
if it is in AUTO_INCREMENT
. And you will notice in the seconde function access_2()
, there's a blank (__________) in $this->db->set('Access_1_ID', ____________);
because there I will input the ID
in the first function access_1()
. It will set only one row for the function access_1()
and in function access_2()
it will iterate because it is inside for each()
. But every iteration I will only get only one ID which has in access_1()
when I set in database.
If you have questions, if you think my explanation seems not understandable, feel free to ask me. Thank you in advance.