Hello!
I ask this question in order to get a doubt I have, and to be able to read other people's ideas, how I can insert or delete an item, a certain operador_id
.
As shown in the first image, when loading a operadores
registration form, I have ready all unidades
registered in the system.
ThenIselectuma
ormais
unit,whoseoperador
shouldbelong.
Andwhenyouclicksave,theobjetooperador
,whichismarkedinredwillbesentasfollows:
Wherewhatisselectedingreen,is(are)theunit(s),whoseoperador
percente.
Lookatthestructureofthedatabase,inthefollowingimage.
My question starts here.
If it is for inclusion, I can use the method, as in the example below:
public function incluir_unidade($dados, $operador_id)
{
$array = (array) $dados;
foreach ($dados as $uni)
{
$unidade = [
'ope_id' => $operador_id,
'uni_id' => $uni->unidade_id,
];
$this->db->insert($this->tb_operador_unidade, $unidade);
}
}
But I wanted to understand, how can I do in case of update:
To insert, exclude unidade(s)
to operador
.
Considering the tables below:
-
Unidade A
exists in the array, but already exists in the database (in this case it does nothing) -
Unidade A
exists in the array and does not exist in the database (in this case, it includes) -
Unidade A
does not exist in array, but exists in database (in this case, database deletion) -
Unidade A
does not exist in the array and does not exist in the database (in this case, it does nothing).
This example is just what I imagine, if there is another way to do it, I'd like to know ..