SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist WebMachine's Avatar
    Join Date
    Jun 2007
    Location
    Ontario, Canada
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dates in "To Do" List

    I have made myself a "To Do" list which I add refinements to every once in a while. I have the following code for selecting the date for which I want the task to be active. Most tasks that I add are for the current date, but sometimes I want to included something to show up in the future.

    So what I would like to do (and can't figure out how) is to have the current date showing on the drop-down menu by default, until I change it if needed.

    I'd be quite happy with just some hints as to what my strategy should be so that I can try to figure out the code. Thanks.

    PHP Code:
    <select name="month">
                            <?php    $month_name = array(JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember);
                            for (
    $i=0$i<12$i++) {
                                
    $month_number $i 1;
                                if (
    $month == $month_number) {
                                    
    $selected "selected=\"selected\"";
                                } else {    
                                    
    $selected "";
                                }
                                print (
    "<option value=\"$month_number\" $selected>$month_name[$i]</option>");
                            }
                            
    ?>
                            </select>
                            <select name="day">
                                <?php
                                    
    for ($i=1$i<=31$i++) {
                                        if (
    $day == $i) {
                                            
    $selected "selected=\"selected\"";
                                        } else {
                                            
    $selected "";
                                        }
                                        print(
    "<option value=\"$i\" $selected>$i</option>");
                                    }
                                
    ?>
                            </select>
                            <select name="year">
                                <option value="<?php print $current_year?>"
                                    <?php
                                        
    if ($year == "$current_year") {
                                            print(
    " selected=\"selected\" >");
                                        } else {
                                            print(
    ">");
                                        }
                                    
    ?>
                                <?php print $current_year?></option>
                                <option value="<?php print $next_year?>"
                                    <?php
                                        
    if ($year == "$next_year") {
                                            print(
    " selected=\"selected\">");
                                        } else {
                                            print(
    ">");
                                        }
                                    
    ?>
                                <?php print $next_year?></option>
                            </select><br />

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hint:

    PHP Code:
    echo date('j'); // prints day 1 to 31
    echo date('n'); //prints month 1 to 12
    echo date('Y'); //prints year 2012


    for ($i=1$i<=31$i++) {
     if (
    $i == date('j') {
      
    $selected "selected=\"selected\""
     } else { 
      
    $selected ""
     } 
     print(
    "<option value=\"$i\" $selected>$i</option>"); 


  3. #3
    SitePoint Evangelist WebMachine's Avatar
    Join Date
    Jun 2007
    Location
    Ontario, Canada
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, so that shows the current date. I could have done that, but I was confusing it with also wanting to change to a different date for the occasional task. Now your hint made me realize that when I change the date, I really don't want it to retain that one but to go back to the current date as the default. doh!! Thanks for clearing that up.

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    So what I would like to do (and can't figure out how) is to have the current date showing on the drop-down menu by default

    Okay, so that shows the current date. I could have done that .....

    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


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
  •