Jump to content

[SOLVED] Blog 'type' archive


timmy0320

Recommended Posts

I don't know why but I've been having some troubles the past couple days trying to figure this out. I'm trying to make a blog 'type' archive for news like so:

 

My page is going to be somethings like archive.php?yr=2008?mon=04

When a current year or month is selected everything that doesn't relate to it will be collapsed.

 

2008 (3)

January (1)

  1 - New Years

February (1)

  14 - Valentines

April (1)

  1 - April Fools

2007 (2)

December

  25-Merry Christmas

  1 - Welcome to the site

 

 

I've been reading up on SQL syntaxs for this and I'm kind of sure that I got the syntax down (please correct me if I'm wrong) but I'm not quite sure on how to implement it into PHP if anyone can give me some help or ideas.

 

Here is what I came up with:

SELECT YEAR (date), MONTH(date), count(*) FROM posts GROUP BY YEAR(date), MONTH(date) ORDER BY date DESC

 

I have really had no luck with finding help on this!

Link to comment
https://forums.phpfreaks.com/topic/99698-solved-blog-type-archive/
Share on other sites

That one is a little different than mine. I will try to implement some of it but I'm trying to display mine like:

 

2008 [2]

-April [2]

--04 - testtt

--01 - This will be the title of the post.

 

 

This is what I have so far:

<?
$results = mysql_query("SELECT DISTINCT YEAR(date) AS `year`, DATE_FORMAT(date, '%m') AS `month`, DATE_FORMAT(date, '%d') AS `day`, count(id) as `posts`, post_title as `title` FROM blog_posts  GROUP BY YEAR(date), DATE_FORMAT(date, '%d') ORDER BY date DESC", $connection);

$posts = array();
while ($row = mysql_fetch_assoc($results)) {
    $post = $row['year'];
    if (!isset($posts[$post])) {
       $posts[$post] = array();
    }
    $posts[$post][] = $row;
}

foreach ($posts as $year => $count) {
    echo '<strong>'.$year .' ['. count($count) .']</strong><br />';
    foreach ($count as $row) {
        echo '  '.$row['month'].'['.count($row['month']).']<br />';
        echo '    '.$row['day'].' - '.$row['title'].'<br />';
      }
    }

?>

 

 

My results are:

 

2008 [2]
  04[1]
    04 - testtt
  04[1]
    01 - This will be the title of the post.
1993 [2]
  04[1]
    14 - test
  03[1]
    15 - testing
1984 [1]
  04[1]
    09 - test

 

I'm slowly getting there.

Archived

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

×
×
  • 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.