0
I have a certain problem in "logic", where I must enter the records of two arrays in a table from BD. There I have the following situation:
In the first if
I check if the tabela_p
does not contain data. If it does not contain, it adds null
in tabela_p
and inserts according to how much data has the 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);
}
}
Just in the else
I enter as per tabela_p
; The problem is:
- If you have a value in
tabela_p
he falls in theelse
and will run for only once. But you have the possibility to contain 2 or more data in thetabela_s
then he won’t insert them.
As I should do to fix this logic?
Do you realize there are some errors in the code? For example, in the first if, where the variable $table_p is set to null, just below you do a for, using $i for the index of the variable $table_p, this will generate an error. for’s for foreach’s
– Raphael Ramos