3
\$\begingroup\$

I am creating a webpage for my newsletter archives. The archives are divided by year (currently there is only 1, but there could be many), then by topic, before listing each newsletter. There will always be exactly five topics, but the number of newsletters in each topic will vary.

I add the name of the newest newsletter in only one place - at the end of the array. I have a link to the most recent newsletter above the rest of the archives.

This code works fine, but the way that I am retrieving the most recent newsletter seems somewhat hacky

The newsletters are currently stored in my server as # segment year.

$newsletter = array(
        "Year 1" => array(
                "First Topic" => array(
                            "a","b","c","d","e","f","g","h","i",
                            ),
                "Second Topic" => array(
                            "j","k","l","m","n","o","ab",
                            ),
                "Third Topic" => array(
                            "cd","ef","fo","er","abd","cdf","eee",
                            ),
                "Fourth Topic" => array(
                            "fff","wet","csg","qqq",
                            ),
                "Fifth Topic" => array(

                            ),
                )
        );

$archive_design = "";

foreach($newsletter as $gilYear => $book){
    $i=1;
    $archive_design .= "<div id=$gilYear class=year>
        <!--<h3> Year $gilYear </h3>-->
        <div class=year-content>";
    foreach($book as $book => $segment){
        $archive_design .= "<div id=$gilYear-$book class=column>
            <b><u>$book</u></b>
            <p></p>
            <ul>
            ";
        foreach($segment as $segment){
            $link = "$i ".strtolower($segment)." ".$gilYear;
            $recent = $segment;
            $i++;
            $archive_design .= "<li>
                                <a href=\"http://example.org/newsletter/$link.pdf\" target='_blank'>$segment </a>
                                <hr/>
                                </li>";
        }
        $archive_design .= "</ul></div><!--end $gilYear-$book-->";
    }
    $archive_design .=  "</div><!--end year-content -->
            </div><!--end $gilYear -->";
}
?>
<html lang="en" >

<body>

<div id="header">
        <a href="http://example.org/newsletter/<?php echo $link; ?>.pdf" target=_blank> Current Issue - <?php echo $recent;?></a></br>

    <h3>Click on the segment to view, download and enjoy the archives!</h3>
</div>

<div id="archives">

<?php 
echo $archive_design;
?>

</div><!--end archives-->
\$\endgroup\$
  • \$\begingroup\$ This question is nearly 1 year old, are you still looking for advice/review on this question? How are you "archiving" your data? Is there a database table? if not, that is the first step in all of this. The second step is generating an auto-incremented id for each newsletter. When you've done these things, please update your question, and I am happy to offer some additional pieces of advice. (Alternatively, if you are no longer seeking assistance, perhaps delete this question so as to remove this abandoned post.) \$\endgroup\$ – mickmackusa Jun 26 '17 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.