I want to display dates between two dates in foreach loop. Suppose the date starts May 1 2014 and ends May 3, 2014 .I want to display like this
//With for loop alone this will display what I wanted
for($i=$dateFrom;$i<=$dateTo;$i++) {
echo $i."<br>";
}
May 1,2014
May 2, 2014
May 3, 2014
But this code returns when using foreach loop to display it is template
May 3,2014
May 3, 2014
May 3, 2014
This is my code in action.php
$dateTo = $r->getParameter("date_to", date('Y-m-d'));
$dateFrom = $r->getParameter("date_from", date('Y-m-d', strtotime('7 days ago', strtotime($dateTo))));
$this->data=array();
foreach($this->deposits as $d) {
$obj = new stdClass();
$obj->created_by = $d->created_by;
$obj->date_created = $d->date_created;
for($i =$dateFrom;$i <= $dateTo;$i++) {
$date=$i;//I think the problem is here.I am not sure how to make this work
}
$obj->amount = $d->amount;
$obj->dateCovered = $date;
$this->data[] = $obj;
}
template.php
<?php foreach ($data as $i => $d): ?>
<tr class="<?php echo ($i%2==0)?'even':'odd' ?>">
<td><?php echo $d->id ?></td>
<td>
<?php echo $d->dateCovered ?>//this will display the last date only
</td>
<td>
<?php $amountTotal += $d->amount ?>
PHP <?php echo number_format($d->amount, 2) ?>
</td>
<td><?php echo $d->created_by ?></td>
<td><?php echo date("F d, Y",strtotime($d->date_created)) ?></td>
</tr>
<?php endforeach ?>
My problem here is it does not display all dates between two dates.Instead it will only display the last date between two dates.What's wrong with this code?