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] Quote Link to comment Share on other sites More sharing options...
tjhilder Posted September 16, 2006 Author Share Posted September 16, 2006 anyone? Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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] Quote Link to comment 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 :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.