Solved

Add link to Archive post code

Posted on 2012-04-05
3
281 Views
Last Modified: 2012-04-05
I am creating a blog and need to have an 'Archive' section.

The year and months display ok using this code...

 <?php foreach ($data as $year => $months) {
    echo $year.'<br>';
    foreach ($months as $month => $count) {
            echo date("F", mktime(0,0,0,$month,1,2000)).'('.$count.')<br>';
    }
} ?>

Open in new window



However, i'm not sure how to add a link. When you click on a month you need to redirect to archive.php and send $month over in the URL so the results page can display all posts from that month.

Any ideas where I add the link to the above code?
0
Comment
Question by:BrighteyesDesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37811767
Maybe something like this?
<?php // UNTESTED CODE
foreach ($data as $year => $months) 
{
    echo $year.'<br>';
    
    foreach ($months as $month => $count) 
    {
        $mnth = date("F", mktime(0,0,0,$month,1,2000));
        $link 
        = '<a href="path/to/script.php?month='
        . $mnth
        . '">'
        . $mnth
        . '</a>'
        . "($count)"
        . '<br/>'
        . PHP_EOL
        ;
        
        echo $link;
    }
}

Open in new window

0
 

Author Comment

by:BrighteyesDesign
ID: 37811850
Ray, you're an absolute superstar, thanks for that!
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37811864
Thanks for the points!  That "vertical layout" for concatenated strings is something I learned from a SQL guru.  I've found that it makes the code very easy to read and get right the first time.  All the best, ~Ray
0

Featured Post

Webinar: MongoDB® Index Types

Join Percona’s Senior Technical Services Engineer, Adamo Tonete as he presents “MongoDB Index Types, How, When and Where Should They be Used?” on Wednesday, July 12, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7).

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question