Welcome Guest, Not a member yet? Register   Sign In
Grouping mysql results in view question
#1

[eluser]BobbyB[/eluser]
Hi,
I have some data in a mysql database with a "datetime" field.
I am displaying that data(using a foreach loop) in my view (sorted by the date) and was wondering how to apply following formatting(grouping it days / or weeks /or months):
Code:
16.06.2010
blabla 1
blabla 2
blabla 3

15.06.2010
blibli 1
blabla 2
blabla 3

14.06.2010
bloblo 1
bloblo 2
blabla 3
blabla 4


Thanks in advance!
#2

[eluser]WanWizard[/eluser]
Assuming that your random text is in a record, and the date is repeated in those records:
Code:
$date = "";
foreach ( $records as $rows )
{
    // do we have to print a header?
    if ( $date != $rows['date'] )
    {
        // print the date header
        $date = $rows['date'];
        echo "<br />",$date,"<br />";
    }
    echo $rows['text'];
}
#3

[eluser]BobbyB[/eluser]
Ahhh,
interesting.
I will try that out.
Thanks for the fast reply.
Cheers!
#4

[eluser]BobbyB[/eluser]
Works like a charm!
Thanks a million times Smile




Theme © iAndrew 2016 - Forum software by © MyBB