I have the below SQL query which returns a result containing financial transactions on a loan, made on specific dates...
$data = array( 'loan_id'=>130 );
$STH = $DBH->prepare("SELECT * FROM ledger WHERE loan_id = :loan_id");
$STH->execute($data);
$STH->setFetchMode(PDO::FETCH_ASSOC);
$row = $STH->fetchAll();
print_r($row);
This gives the following result
Array (
[0] => Array (
[ledger_id] => 38
[loan_id] => 130
[ledger_type_id] => 1
[amount] => 1.20
[ledger_date] => 2016-07-25
)
[1] => Array (
[ledger_id] => 39
[loan_id] => 130
[ledger_type_id] => 3
[amount] => 0.90
[ledger_date] => 2016-08-15
)
[2] => Array (
[ledger_id] => 40
[loan_id] => 130
[ledger_type_id] => 2
[amount] => 0.30
[ledger_date] => 2016-09-19
)
)
I now need to loop through all dates that the loan has been active, and find the 'ledger_type_id' and 'amount' for transactions that occurred on the current date in the loop. The ledger table does not contain a record for every day, however I need to look at each individual day that the loan has been active for other purposes not relevant to this question.
$start_date = new DateTime('2016-07-13');
$today = new DateTime();
$today = $today->modify( '+1 day' ); // add one day to include today
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($start_date, $interval ,$today);
foreach ($daterange as $date) {
/*
The above SQL query returns a row with the 'ledger_date'
of '2016-08-15'
I need to find the value of the ledger_type_id
for the same row from the above query
when $date = '2016-08-15' in this loop
*/
// Do other unrelated stuff on each day of the loop.....
}
I have tried a few things using in_array() but without success.