Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Add link to Archive post code

Posted on 2012-04-05
3
Medium Priority
?
287 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
  • 2
3 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

916 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