1
I have a Mysql table where the primary entries are 3 columns: YEAR, NUMBER and PORTION.
The NUMERO column is a sequential numbering for each YEAR, but it is possible that for the same number there are several PARCELS.
I need to perform a SELECT with arrays, where I have an array for YEAR, another for NUMERO and another for PARCEL.
The fact is that if I use "IN", it does not bring the number associated with the YEAR and the PLOT.
For example:
ANO NUMERO PARCELA
17 5673 1
17 6783 1
18 5673 1
18 6790 1
I create the following entries $year = ('17', '18'), $number = ('5673', '6790') and $Parc = ('1', '1'), when performing the following query:
SELECT * FROM table WHERE ANO IN($ano) AND NUM IN($numero) AND PARC IN($parc)
The result will be:
17 -> 5673 -> 1
18 -> 5673 -> 1
18 -> 6790 -> 1
Since what I desire is:
17 -> 5673 -> 1
18 -> 5673 -> 1 <---- SEM ESSE RESULTADO
18 -> 6790 -> 1
That is, I want each entry of the "array" $year to be associated with the entry of the "array" $numero, associated with the entry of the "array" $Parc.
I don’t quite understand what you want. What do you mean in
cada entrada da "array"
? You say you need it to bring in the order you’re in$ano = ('17', '18'), $numero = ('5673', '6790') e $parc = ('1', '1')
? That is, 17 - 5673 - 1 and 18 - 6790 - 1 ? If so, it is wrong to use IN. If you have onearray
, loop it by filtering 1 to 1. This$ano = ('17', '18')
is not an array. It would be$ano = array('17', '18')
, and then I could do theforeach
.– rbz