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

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.