field names in for loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hozyali
    New Member
    • Mar 2007
    • 5

    field names in for loop

    Hi,

    If you go to http://projects.starco msystems.net/golfcenter
    then select number of rounds, the page reloads and copies the TeeTime and Day fields according to the number selected for rounds.

    Currently its just a for loop which takes the querystring of rounds and copies the two fields. I need to know that how will we parse the copied fields values to the next page?

    Currently I tried to simply name the two fields with the loop counting variable which is not be fetched on the next page and gives an error.

    can some one please advise.

    Regards
    Ali
  • devsusen
    New Member
    • Feb 2007
    • 136

    #2
    Originally posted by hozyali
    Hi,

    If you go to http://projects.starco msystems.net/golfcenter
    then select number of rounds, the page reloads and copies the TeeTime and Day fields according to the number selected for rounds.

    Currently its just a for loop which takes the querystring of rounds and copies the two fields. I need to know that how will we parse the copied fields values to the next page?

    Currently I tried to simply name the two fields with the loop counting variable which is not be fetched on the next page and gives an error.

    can some one please advise.

    Regards
    Ali
    I think you shouldn't have any error in fetching the fields. I am not sure why r u using Rnd in URL in form action part. Try to print all the form variable using
    Code:
    print_r($_REQUEST);
    Then u will have an idea what r the value going in the next page.

    susen

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      I can, of course, not see how your php processing is done, but 'll give it a try.

      When the number of rounds is entered, you can save that number in the form as a hidden field, say that number is in php variable $rounds, you append the next statement to the form:

      [php]<input type='hidden' name='rnd' value='<? echo $rounds ?>' />[/php]
      I can see that you assign the names of the fields using a counter, i.e. first tee date is in 'firstinput1', the second tee date is in 'firstinput2', etc. For the times the first tee time is in 'TeeTime1', the second in 'TeeTime2', etc.

      When the form is submitted, first you do is to get the number of round from the $_POST string. Then you use this counter '$rnd' in a loop to process the tee dates and tee times and store them in an array, like this:

      [php]
      if (isset($_POST['rnd'])) {
      $rnd = $_POST['rnd'];
      $date_time=arra y();
      for ($i=1; $i <= $rnd; $i++) {
      $date_time[$i]['date'] = $_POST['firstinput'.$i];
      $date_time[$i]['time'] = $_POST['TeeTime'.$i];
      }
      echo '<pre>'; print_r($date_t ime);
      }
      [/php]
      The last statement prints out the array you built, so you can see what is in it. Good luck. When you have any more problems with this snippet or your script, let us know.

      Ronald :cool:

      Comment

      Working...