Results 1 to 4 of 4
  1. #1
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Location
    Mobile, Alabama
    Posts
    1,220
    [php] Self-Updating Select Menu
    I've got a month/year select menu that I'm tired of having to update manually, I often forget about it for a month or so. I've wanted to automate it for a while but have never been able to figure it out. I can do individual selects (month, day, year) but I've never figured out how to combine them.

    I've found this code which does a certain number of continous days, and it's the only thing I've found, so far, combined. Every other search turns up individual selects. I've tried to alter it to suit my needs but I'm stuck.

    Of course it needs to be April 2006, May 2006, ...., January 2007, February 2007, etc.

    I'm not even sure it's possible with the current setup. I'm not a mktime() person.

    My code:

    PHP Code:
    <?
       $size
    ="18";
       
    $default date("n/1/Y");
       echo 
    "<select name=\"Month\" class=\"form\">\n";
       for (
    $i 0$i <= $size$i++) {
          
    $theday mktime(date("F"), date("Y"));
          
    $option=date("F Y",$theday);
          
    $value=date("n/1/Y",$theday);
          if (
    $value == $default) {
             
    $selected="selected=\"selected\"";
          }
             echo 
    "<option value=\"$value\" $selected>$option</option>\n";
       }
       echo 
    "</select>\n";
    ?>
    Which gives me:

    Code:
    <select name="Month" class="form">
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    <option value="4/1/2006" selected="selected">April 2006</option>
    </select>

    Shawn Kerr (.com) | Disney World | SEC Football

  2. #2
    Lite On The Do, Heavy On The Nuts Donuts's Avatar
    Join Date
    January 18th, 2005
    Location
    Winter Park, FL
    Posts
    6,930
    In your FOR loop, you don't have anything incrementing...

    Notice that your counter variable ($i) is not in this line:
    $theday = mktime(date("F"), date("Y"));

    Nor is any code to bump $theday to the next consecutive month...

    There's a number of ways you could do it, but I think identifying your problem is most of your battle right now... and the problem is looping without any code that causes incrementing any values.

  3. #3
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Location
    Mobile, Alabama
    Posts
    1,220
    Yeah, I tried adding $i to one, the other and both date()'s in the $theday variable. It didn't change anything at all. In the original code it's on the day date() but since the day is not part of the equation I need, then I wasn't sure where to go next.

    But I think I am going back to searching, been staring at this code for way too long.

    Shawn Kerr (.com) | Disney World | SEC Football

  4. #4
    Lite On The Do, Heavy On The Nuts Donuts's Avatar
    Join Date
    January 18th, 2005
    Location
    Winter Park, FL
    Posts
    6,930
    See the section called "PHP Date - Supplying a Timestamp" here:
    http://www.tizag.com/phpT/phpdate.php
    (about halfway down the page)

    It shows how you can increment the day part of the date... you could do the same thing to the month part of the date.

    Have fun!

  5. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. I need help with a php drop down menu
    By tsmgroup2 in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: June 26th, 2007, 01:18 AM
  2. PHP Menu Script
    By John Powell in forum Programming / Datafeeds / Tools
    Replies: 7
    Last Post: January 4th, 2006, 03:39 PM
  3. Help with PHP Select statement
    By Doug247 in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: July 30th, 2004, 12:01 PM
  4. Is there a Select Case in PHP?
    By Doug247 in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: May 5th, 2004, 01:09 PM

Posting Permissions

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