Jump to content

Archived

This topic is now archived and is closed to further replies.

tjhilder

[ solved ] trying to organize categories into month/year by date *solved*

Recommended Posts

Hi,
(ok i decided to rewrite my problem, maybe the last one was a bit confusing)

update on 22nd Sept 06:
------------

i'm basicly trying to do this:

i have some rows of info, say:

(album_name) (date (IN 0000-00-00 00:00:00 THEN use UNIX_TIMESTAMP() AND THEN FORMATTED))
album3 2006-01-02
album2 2006-01-01
album1 2005-12-31

what I want to do is that it lists it like this:

2006
January
album3 2nd
album2 1st

2005
December
album1 31st

----------------------

using the 0000-00-00 00:00:00 format I want to seperate them by month and year into their own groups.

here's what it looks like now: [url=http://www.48oz.co.uk/gallery/view.php]http://www.48oz.co.uk/gallery/view.php[/url] <-- show's you how it's resuting

and here's the php / mysql code: [url=http://www.48oz.co.uk/gallery/view.txt]http://www.48oz.co.uk/gallery/view.txt[/url]

[b]can anyone please help with some simple code?[/b]

Share this post


Link to post
Share on other sites
you have to group your sql then a few if thens in your code. I have exactly what your looking for if you give me a breakdown of your table I will pass the code on to you.

Ray

Share this post


Link to post
Share on other sites
try
[code]
<?php
$sql = "SELECT album_name, YEAR(date) as year, MONTHNAME(date) as month, date
    FROM mytablename ORDER BY date DESC";
   
$res = mysql_query($sql) or die(mysql_error());
$lastYear = $lastMonth = '';

while (list($album, $year, $month, $dt) = mysql_fetch_row($res)) {

    if ($lastYear != $year) {
        echo "<h3>$year</h3><h4>$month<h4>";
    }
    elseif ($lastMonth != $month) {
        echo "<h4>$month<h4>";
    }
    echo $album . ' ' . date('jS', strtotime($dt)) . '<br/>';
    $lastYear = $year;
    $lastMonth = $month;
}
?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.