SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    436
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    how to pass the value and show article title list?

    i want to echo something like the following in a file(eg: test.php).

    ....
    201105
    201106
    201107
    201108
    201109
    201110
    ....
    the code output it may be:

    Code:
    $months = 10; //count of months 
    $date = date_create( 'now' );
    echo date_format( $date, 'Y M' );
    for ( $i = 0; $i < $months; $i++ ) {
        date_sub( $date , date_interval_create_from_date_string( '1 months' ) );
        echo date_format( $date, 'Y M' );
    }
    i fell the code isn't very good. the above is the year-month archive. now i want to when the user click the year-month. then in the current page shows each articles' title with list that belong to the year-month. i know i should use a passed value into my database query then select out each articles' title.supposed each article created time is stored as this 15806927473. but i don't know how to passed the value. when the user click the year-month. and use the passed value in my sql query. thank you.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,396
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Pass the year and the month in the query string of the link (f.e. page.php?yearmonth=201105).
    Use that value in the called php script ($_GET['yearmonth']).

    each article created time is stored as this 15806927473
    You'll have to transform the yearmonth value into this date format before using it in the query.

  3. #3
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    436
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i am sorry, i am new of php,. could you give me a simple example?

  4. #4
    SitePoint Member
    Join Date
    May 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guido2004 is right, a simple example would be this

    test.php echo out some sort of html, the year and month are presumable links,
    just echo out the dates as well into ur a href e.g.

    Code:
    <a href="sompage.php?date=201105">201105</a>
    then the somepage.php could have something like this

    PHP Code:

    $date 
    $_GET['date']; // eg. 201105 

    and that should do it!


Bookmarks

Posting Permissions

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