SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: The While Loop

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    Florida
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    The While Loop

    Hi all. I am just learing php using Larry Ullman's PhP for the World Wide Web. The lesson I'm working on lets the visitor select the date using dropdown menus. Once I finished writing the script, the month and day are working perfectly. The year however, is showing as 1 - 10, instead of 2000 - 2010.

    The script for the year is"

    // Create the year pull-down menu.
    $EndYear = $Year + 10;

    while ($Year <= $EndYear ) {
    print("<option value=$Year>$Year</option>\n");
    $Year++;
    }

    print ("</select>\n");
    print ("<p><input type=submit name=submit value=\"Go!\"></form>\n");


    You can see what I mean for yourself at http://iwdtestsite.com/ControlStructures/select.php.

    Thank you in advance for your help.

  2. #2
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Without seeing where the value $Year is set, I can only guess that $Year isn't being set at all, or more likely, isn't being set to the current year.

    ?Immediately? above the code you should have a line along the lines of :

    PHP Code:
     $Year = (int)date('Y'); 
    My name is Steve, and I'm a super-villian.

  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)
    From looking at your form, I would have to concur with lieut_data on this one. It doesn't seem that your $year value is set.

    As long as you set your the value for $Year as lieut_data showed you above you should be alright.
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    Florida
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you guys. That took care of the problem. I appreciate your quick replies.

    Magikey


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
  •