[eluser]epseix[/eluser]
Right, I have another question - this time about defining variables within a foreach loop.
Before I moved over to Codeigniter framework, the following query worked:
Code:
<?php if ($year != date('Y', strtotime($row['datetime']))):
$year = date('Y', strtotime($row['datetime'])); ?>
<h2><?=$year?></h2>
<?php endif;?>
<h3><?=$month?></h3>
<h4><?=$day?></h4>
Now that I'm using Codeigniter, there's 2 issues I can see - 1) the foreach loop and 2) the view file should be purely html. Plus, even with the following, the variable year is undefined and a php error flags up...
Code:
<?php if (isset($future)):
foreach ($future as $row):?>
if ($year != date('Y', strtotime($row->datetime))):
$year = date('Y', strtotime($row->datetime));?>
<h2><?=$year?></h2>
<?php endif;?>
<h3><?=date('F', strtotime($row->datetime))?></h3>
<h4><?=date('D, jS', strtotime($row->datetime))?></h4>
<? endforeach;?>
<?php endif;?>
To clearly explain what I'm trying to achieve; I want to generate a result like so:
Code:
<h2>2013</h2>
<h3>Jan</h3>
<h4>Sun, 2nd</h4>
<h3>Feb</h3>
<h4>Sun, 3rd</h4>
As opposed to:
Code:
<h2>2013</h2>
<h3>Jan</h3>
<h4>Sun, 2nd</h4>
<h2>2013</h2> ** This line needs to go etc. **
<h3>Feb</h3>
<h4>Sun, 3rd</h4>
Any help is greatly appreciated!