SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Sort years

  1. #1
    SitePoint Addict Smolf3d's Avatar
    Join Date
    Aug 2004
    Location
    russia
    Posts
    224
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question Sort years

    On this code , start in 1908, end in 2008

    PHP Code:
            echo "<select name=\"year\" class=\"1\">";
            
    $date getdate();
            
    $year $date['year'] - 100;
            
    $getyear 0+$_GET['year'];
            while (
    $year <= $date['year']) {
                
    $sel = ($year == $getyear) ? "selected=\"selected\"" "";
                echo 
    "<option value=\"$year\" $sel>$year</option>";
              
    $year++;  
            }
            echo 
    "</select>"
    How sort, start 2008, end 1908 ?

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try (not tested)
    PHP Code:
      echo "<select name=\"year\" class=\"1\">";

            
    $date getdate();

            
    $year $date['year'];

            
    $getyear 0+$_GET['year'];

            while (
    $year >= ($year 100)) {

                
    $sel = ($year == $getyear) ? "selected=\"selected\"" "";

                echo 
    "<option value=\"$year\" $sel>$year</option>";

              
    $year--;  

            }

            echo 
    "</select>"
    ---------------------------
    Errors = Improved Programming.
    My Site

  3. #3
    SitePoint Enthusiast snajt's Avatar
    Join Date
    May 2008
    Location
    Kalmar, Sweden
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this

    PHP Code:
    <?php
    $min_year 
    date('Y');
    $max_year $min_year 100;

    $years range($min_year$max_year);

    foreach(
    $years as $year)
    {
        echo 
    $year '<br />';    
    }

  4. #4
    SitePoint Addict Smolf3d's Avatar
    Join Date
    Aug 2004
    Location
    russia
    Posts
    224
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    snajt - you version work!

    Thanks jaswinder_rana and snajt


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
  •