Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Add link to Archive post code

Posted on 2012-04-05
3
Medium Priority
?
285 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
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 …

670 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