SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2004
    Location
    new mexico
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trouble with a date select box

    I have this date select box (for months only )

    PHP Code:
    echo "<form action=\"index.php\" method=\"GET\">\n";
                    echo 
    "<table border=\"1\">\n";
                        echo 
    "<th colspan=\"2\">View Other Months</th>\n";
                        echo 
    "<tr>\n";
                            echo 
    "<td>\n";
                                echo 
    "<select name=\"months\">\n";
                                    foreach (
    $months as $key => $val ) {
                                        (
    $key == date('m'time())) ? ($sel " selected") : ($sel "");
                                        echo 
    "<option value=\"".$key."\"$sel>".$val."</option>\n";
                                    } 
    When i select a month earlier than the current month ( october so fa ), there is 10 added to the month. January become 11, February becomes 12 and so on.

    I have tried to change it here:
    PHP Code:
    echo "<form action=\"index.php\" method=\"GET\">\n";
                    echo 
    "<table border=\"1\">\n";
                        echo 
    "<th colspan=\"2\">View Other Months</th>\n";
                        echo 
    "<tr>\n";
                            echo 
    "<td>\n";
                                echo 
    "<select name=\"months\">\n";
                                    foreach (
    $months as $key => $val ) {
                                        (
    $key == date('m'time()-10)) ? ($sel " selected") : ($sel "");
                                        echo 
    "<option value=\"".$key."\"$sel>".$val."</option>\n";
                                    } 
    But i haven't solved it yet.

    Any ideas??

  2. #2
    SitePoint Zealot devscripts's Avatar
    Join Date
    Sep 2004
    Location
    ur monitor
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry i misunderstand you. can you explain a little more?

  3. #3
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure why you are making it so complicated for just a month selector. Why don't you just code out the months? Are you simply wanting the current month to be the initially selected option?
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  4. #4
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo '
    <form action="index.php" method="GET">
    <table border="1">
    <th colspan="2">View Other Months</th>
    <tr>
    <td>
    <select name="months">
    '
    ;
    $monthnames = array('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');
    $thismonth date('m'time());
    $n 1;
    foreach (
    $monthnames as $name) {
        if (
    $n == $thismonth) {
            
    $sel ' selected';
        } else {
            
    $sel '';
        }
        echo 
    "<option value=\"$n\"$sel>$name</option>\n";
        ++
    $n;
    }
    echo 
    '
    </select>
    </td>
    </tr>
    </table>
    '


  5. #5
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good look arbor. nm that code should do exactly what you want (if we understand you correctly) in a much less complicated way!
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!


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
  •