Forum Moderators: coopster
>>
index.htm
>>
textbox: input number of records to insert ___3___
>>
script.php
first _______ last ___________
first _______ last ___________
first _______ last ___________
do i loop like..? or how should it be?
<?php
$number = $_GET['number'];
for ($i = 0; $i <= $number; $i++)
{
echo"<input type=text name=first" . $i . ">";
echo"<input type=text name=last" . $i . "> <br>";
}
?>
now, how about passing this to the database? help please.
<input type=hidden name=number value=<? echo $number;?>> Now that you've stored the number, when they fill out the form and click submit, you can take the number, make a similar loop and read through each of the input variables. It might look something like this:
<?php
$number = $_GET['number'];
for ($i = 0; $i <= $number; $i++)
{
$first = $_GET['first'.i];
$last = $_GET['last'.i];
/* Do the Insert Here */
}
?>
Another way to do it would be to not add the number to the end of the first and last inputs names. When the form is filled out and submitted, you would end up with 2 arrays (first and last) that you could loop through with php. They will both be of the same length so you could loop through one and pull from both. For this to work, you could add the hidden input (number) like above or you can probably get the number from the array itself.
-=casey=-