tjhilder Posted September 16, 2006 Share Posted September 16, 2006 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-02album2 2006-01-01album1 2005-12-31what I want to do is that it lists it like this:2006Januaryalbum3 2ndalbum2 1st2005Decemberalbum1 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 resutingand 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 https://forums.phpfreaks.com/topic/20967-solved-trying-to-organize-categories-into-monthyear-by-date-solved/ Share on other sites More sharing options...
tjhilder Posted September 16, 2006 Author Share Posted September 16, 2006 anyone? Link to comment https://forums.phpfreaks.com/topic/20967-solved-trying-to-organize-categories-into-monthyear-by-date-solved/#findComment-93261 Share on other sites More sharing options...
tjhilder Posted September 22, 2006 Author Share Posted September 22, 2006 ok I changed my original message, maybe it's easier to understand? Link to comment https://forums.phpfreaks.com/topic/20967-solved-trying-to-organize-categories-into-monthyear-by-date-solved/#findComment-96901 Share on other sites More sharing options...
craygo Posted September 22, 2006 Share Posted September 22, 2006 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 Link to comment https://forums.phpfreaks.com/topic/20967-solved-trying-to-organize-categories-into-monthyear-by-date-solved/#findComment-96922 Share on other sites More sharing options...
Barand Posted September 22, 2006 Share Posted September 22, 2006 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 https://forums.phpfreaks.com/topic/20967-solved-trying-to-organize-categories-into-monthyear-by-date-solved/#findComment-96939 Share on other sites More sharing options...
tjhilder Posted September 22, 2006 Author Share Posted September 22, 2006 thanks a lot, Barand, it works perfect :) Link to comment https://forums.phpfreaks.com/topic/20967-solved-trying-to-organize-categories-into-monthyear-by-date-solved/#findComment-97005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.