Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 tjhilder

tjhilder
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationKent, UK

Posted 16 September 2006 - 11:56 AM

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: http://www.48oz.co.uk/gallery/view.php <-- show's you how it's resuting

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

can anyone please help with some simple code?

#2 tjhilder

tjhilder
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationKent, UK

Posted 16 September 2006 - 11:00 PM

anyone?

#3 tjhilder

tjhilder
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationKent, UK

Posted 22 September 2006 - 07:21 PM

ok I changed my original message, maybe it's easier to understand?

#4 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 22 September 2006 - 07:44 PM

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

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 22 September 2006 - 08:11 PM

try
<?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;
}
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 tjhilder

tjhilder
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationKent, UK

Posted 22 September 2006 - 11:04 PM

thanks a lot, Barand, it works perfect :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users