Jump to content

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


tjhilder

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]
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.