$query = "SELECT A.Date, B.Fee
FROM [Client] A JOIN [Price] B
ON A.SID = B.SID
WHERE A.Date BETWEEN '$from' AND '$to' AND A.ClientID = '$client'
ORDER BY A.Date";
I use the above query to display fee of transactions in a period (usually monthly), and where there's no transaction in a day it should display the fee from the last day transaction while there's no transaction data on that day. For example I wanna display this:
2015-01-05 | 234,567
2015-01-06 | 123,456
2015-01-07 | 123,456 // this is taken from 0106 cause no transaction on Sat
2015-01-08 | 123,456 // this is taken from 0106 cause no transaction on Sun
2015-01-09 | 345,678
While the data in database:
2015-01-05 | 234,567
2015-01-06 | 123,456
2015-01-09 | 345,678
I use the code below to display the data, and to do the trick currently, I re-query the data from date+1 and date+2 and display the friday's data. The problem is that won't do it when it's holiday (and I don't think that's efficient).
$stmt = $con->prepare($query);
$stmt->execute();
$rows = $stmt->fetchAll();
$num = count($rows);
foreach ($rows as $row) {
echo date('d-m-Y', strtotime($row['Date']));
echo number_format($row['Fee'], 0, ",", ".");
}
I'm hoping for a solution.