View Single Post
Old 12-20-2007, 07:37 PM   #10 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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];
    }

Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
codefreek (01-08-2008)