RathanakBun Posted April 25, 2013 Share Posted April 25, 2013 for ($i=1;$i<10;$i++) { if (isset($_POST['btnsubmit'])) { $fram=$_POST['fram_'.$i]; $year=$_POST['year_'.$i]; $ton=$_POST['ton_'.$i]; $model=$_POST['model_'.$i]; echo $fram."\t"; echo $year."\t"; echo $ton."\t"; echo $model."\t"; echo "<br>"; } } This code above will show variable till 9 but i want to show only sometime 2 or sometime 3 or sometime 5 how can i close other variable what code i can use or what function ? Quote Link to comment https://forums.phpfreaks.com/topic/277280-ulimited-get-variable-from-form-to-_post/ Share on other sites More sharing options...
Psycho Posted April 25, 2013 Share Posted April 25, 2013 First off, change your field names so the groups of fields will be in an array Car 1: <input type="text" name="cars[0][fram]" /> <input type="text" name="cars[0][year]" /> <input type="text" name="cars[0][ton]" /> <input type="text" name="cars[0][model]" /> Car 2: <input type="text" name="cars[1][fram]" /> <input type="text" name="cars[1][year]" /> <input type="text" name="cars[1][ton]" /> <input type="text" name="cars[1][model]" /> . . . .etc. Now, you can iterate over each group of fields in a more simple/logical manner foreach($_POST['cars'] as $car) { echo "{$car['fram']}\t{$car['year']}\t{$car['ton']}\t{$car['model']}\t<br>"; } As for limiting the number of records you process - it all depends. If you limit the number of field sets that are created then the foreach() loop will work perfectly. Else, if you will always have 10 fieldsets but only want to process n, then you can use array_slice() to trim the array to the number of elements you want. Quote Link to comment https://forums.phpfreaks.com/topic/277280-ulimited-get-variable-from-form-to-_post/#findComment-1426484 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.