I have a certain problem in "logic", where I should insert the records of two arrays into a table of the DB. Here I have the following situation:
At first if
I check that tabela_p
does not contain data. If it does not contain, it adds null
to tabela_p
and inserts according to how much data it has tabela_s
;
if(count($tabela_p) == 0){
$tabela_p = null;
for( $i = 0; $i < count( $tabela_s); $i ++ ) {
$w_querybusca="insert into sai_cad_patr_seri (fk_seq_cara_peri,tx_num_patr,tx_num_seri)
values ('$arr_w_param[17]','$tabela_p[$i]','$tabela_s[$i]');";
$w_queryresultado = f_class_conecta_bd($w_querybusca);
}
}
else
{
for( $i = 0; $i < count($tabela_p); $i ++ ) {
$w_querybusca="insert into sai_cad_patr_seri (fk_seq_cara_peri,tx_num_patr,tx_num_seri)
values ('$arr_w_param[17]','$tabela_p[$i]','$tabela_s[$i]');";
$w_queryresultado = f_class_conecta_bd($w_querybusca);
}
}
Soon in else
I enter as tabela_p
; The problem is:
- If it has a value in
tabela_p
it falls intoelse
and will execute it only once. But it has the possibility to contain 2 or more data intabela_s
ai it will not insert them.
How should I do to fix this logic?