Creating fields in a table based on a drop-down selection

Hi all,
I have a drop-down with the label " How many people...".and the values of 1,2,3,4 etc... I want the selected value of this drop-down to generate the correct amount of rows in a table. For example if the user selects 2 people, then two rows are added to a table so the user can enter personal information about them? Any suggestions as to the easiest way to do this?
Thanks,
D
dereksheahanAsked:
Who is Participating?
 
Jason C. LevineConnect With a Mentor No oneCommented:
Hi derek,

The concept is similar to creating a repeat region.  Put this code in where you want the table to start:

<?php

echo "<table>";

$i = 0; // start the counter here

while ($i < $_POST['theformfieldwiththenumber']) {

echo "<tr><td></td></tr>\n";

}

$i++;

if ($i == $_POST['theformfieldwiththenumber']) { echo"</table>\n"; }

?>


This while loop should produce the correct number of rows.  If the form is using GET, change the above from _POST to _GET.  Put whatever you like in the first echo statement or expand it into multiple statements.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.