SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: PHP date

  1. #1
    SitePoint Zealot cools_sonu's Avatar
    Join Date
    Jan 2010
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP date

    Hello all.

    I'm developing a site, in which there is a field named "Date of Birth."

    I want to automate that field with select options and and within a predefined range of years. but I'm unable to put the logic in the correct order.

    please help me ?

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    • Output a select HTML tag
    • Loop through years, outputting an option tag each loop
    • Output the ending HTML select tag


    Or, if you want the full code and because I'm feeling extra generous :P

    PHP Code:
    echo '<select name="Year">';
    for(
    $Year 1901$Year <= 1992$Year++){
        
    printf('<option value="%1$s">%1$s</option>'$Year);
    }
    echo 
    '</select>'
    Last edited by Jake Arkinstall; Mar 10, 2010 at 17:28. Reason: Semi colon blues :P
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Zealot cools_sonu's Avatar
    Join Date
    Jan 2010
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Quote Originally Posted by Jake Arkinstall View Post
    • Output a select HTML tag
    • Loop through years, outputting an option tag each loop
    • Output the ending HTML select tag


    Or, if you want the full code and because I'm feeling extra generous :P

    PHP Code:
    echo '<select name="Year">'
    for($Year 1901$Year <= 1992$Year++){
        
    printf('<option value="%1$s">%1$s</option>'$Year);
    }
    echo 
    '</select>'
    Thanx Jake

    Actually I was thinking the other way, means in the php's date function way, and i.e. where I was struck..

    Thanx for the help. Now I can automate the other two fields too, of month and day.

    Yo!!

    Logic was simple but I was thinking the other way... lol..


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
  •