12-20-2007, 07:37 PM
|
#10 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
To summarise the comments saying to use a second for loop, here's a visual example.
PHP Code:
// First loop, to output the form elements
for ($i = 1; $i <= 3; $i++)
{
printf('<input type="text" name="a%d" value="%d" /><input type="submit" name="submit%d" value="Submit" />', $i, $i, $i);
// or, see: http://www.talkphp.com/showthread.php?t=1129
// printf('<input type="text" name="a%1$d" value="%1$d" /><input type="submit" name="submit%1$d" value="Submit" />', $i);
}
// Second loop, to respond if the form was posted
for ($i = 1; $i <= 3; $i++)
{
// Alternative: isset($_POST['submit' . $i])
if (array_key_exists('submit' . $i, $_POST))
{
echo $_POST['a' . $i];
}
}
|
|
|
|