Answer the question
In order to leave comments, you need to log in
How to group records by year?
Good afternoon!
There are many events and the year of their origin, for example:
2013 - event 1
2013 - event 2
2013 - event 3
2012 - event 4
2011 - event 5
There is no way to group them so that they can be displayed in such a form:
2013:
- event 1
- event 2
- event 3
2012:
- event 4
2011:
- event 5
I take data from the database and sort it by year in descending order
I would be grateful for any help!
Everything worked out, I did this:
<?
$j = 0;
if ($i == 0) {
$tempYear = $year;
echo $tempYear;
}
if (($i - $j == 1) && ($i != 0) ) {
if ($tempYear != $year) {
$tempYear = $year;
echo $tempYear;
}
$j++;
}
?>
Answer the question
In order to leave comments, you need to log in
<?
$j = 0;
if ($i == 0) {
$tempYear = $year;
echo $tempYear;
}
if (($i - $j == 1) && ($i != 0) ) {
if ($tempYear != $year) {
$tempYear = $year;
echo $tempYear;
}
$j++;
}
?>
$year = 0;
while($row = $db->fetch()){
if($year!=$row['year']){
$year = $row['year'];
echo $year;
}
echo $row['event'];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question