0
I have a Array of records:
Array
(
[0] => Array
(
[HANDLE] => 1
[Z_GRUPO] =>
[EMPRESA] => 1
[FILIAL] => 1
[DATAINICIO] => 2018-01-01
[CONSUMO] => 2
[VEICULO] => 82
)
[1] => Array
(
[HANDLE] => 2
[Z_GRUPO] =>
[EMPRESA] => 1
[FILIAL] => 1
[DATAINICIO] => 2018-02-01
[CONSUMO] => 2.5
[VEICULO] => 82
)
[2] => Array
(
[HANDLE] => 3
[Z_GRUPO] =>
[EMPRESA] => 1
[FILIAL] => 1
[DATAINICIO] => 2018-03-01
[CONSUMO] => 3
[VEICULO] => 82
)
[3] => Array
(
[HANDLE] => 4
[Z_GRUPO] =>
[EMPRESA] => 1
[FILIAL] => 1
[DATAINICIO] => 2018-02-01
[CONSUMO] => 3.5
[VEICULO] => 102
)
)
Question:
Would like to search in the Array having as reference a DATE AND A VEHICLE.
Example:
What is the CONSUMPTION of VEICULO 82 in DATA 10/02/2018?
If it were a database, it would simply be this:
SELECT TOP 1 * FROM VEICULOCONSUMO
WHERE VEICULO = 82
AND DATAINICIO <= '10/02/2018'
ORDER BY DATAINICIO DESC
The correct return would be: 2.5
How the record was made in 10/02/2018, then the most recent or equal previous date was [1][DATAINICIO] => 2018-02-01.
The "X" of the question is how to pull the CONSUMPTION referring to DATE and VEHICLE, where the DATE equals START OR LATEST DATE.
DATAINICIOis astring? This data comes from where, from the database ? If it is the case it is not easier to bring soon what you want, with the query that exemplified ?– Isac
@Isac the date comes in this format that I’m finding strange sqlsrv_fetch_array returns timedate field as object... It comes from a BD but I bring other related records, so there is no way to make association in the query...
– rbz