SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2012
    0 Post(s)
    0 Thread(s)

    Building an archive for an online journal with php and mysql


    I am trying to build an archive for a website that will be publishing journals. However, I am having challenges building the archive where past journals will be stored and retrieved for future references and reading. My major challenge is how to retrieve the datetime from the DB and display it by year first and when a particular year is clicked it takes one to the months and when a month is clicked, the publications for the month are displayed for the interested reader to pick from. A sample of this is I will need assistance on this.

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    France, deep rural.
    17 Post(s)
    1 Thread(s)
    So, how about you start with the year picker?
    PHP Code:
    // You know which year your archive started in, so assign that to a variable.
    $start_year 2001;
    // The end year will presumably be this year
    $this_year date("Y");

    // in this case create a select box, but you could just as easily be creating a table
    $years "<select name=year>"PHP_EOL ;

    $y=$start_year$y <= $this_year $y++  ){

    // concatenate the html options to the string 
    $years .=  "<option value=$y>$y</a>" PHP_EOL ;


    // concat the end of the string
    $years .= "</select>" .  PHP_EOL ;
    // further on, in your html form echo out the select box containing the years
    echo $years ;

    That will help you create a html form which submits a value called "year", if your form uses the POST method you grab that with $_POST['year'].

    You need to check that value is as expected, a number between 2000 and 2012 and then you are free to show months.

    Either show all months for that year, or as in your example show months which do have corresponding entries.

    How are you storing dates in your database?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts