havik Posted September 29, 2008 Share Posted September 29, 2008 hello, on a form i got this code <?php //opzoeken aantal max toegelaten claims $opzoeken = "select waarde FROM ".$db_pf."config WHERE conf = 'max'"; $resultaat = mysql_query($opzoeken); $maxcl = mysql_fetch_object($resultaat); //vaste variable om reeks aan te maken $teller = "1"; $maxclaims = ($maxcl->waarde); //weergave van een nieuwe claimlijn zolang als $teller niet groter is dan het max aantal claims while ($teller <= $maxclaims) { //aanpassen van variable cordx en corxy ifv aantal claim lijnen echo "<tr><td>claim ".$teller."</td><td colspan = 2><input type='text' name='cordx".$teller."' size='3'>|<input type='text' name='cordy'".$teller." size='3'></td></tr>"; //teller verhogen $teller ++; } ?> as u can see the varibles cordx and cordy get a number behind them depending on the value of $teller my problem is that when the user submids the data i need a way to get all the $_POST['cordx(number)'] and $_POST['cordy(number)'] i know i can start the same way with a while loop but how can i chane the number in the $_POST variable hope i'm making sence here , and ty for reading Havik Link to comment https://forums.phpfreaks.com/topic/126323-getting-variable-_post/ Share on other sites More sharing options...
Dragen Posted September 29, 2008 Share Posted September 29, 2008 do you mean something like this? for($i = 0; $i < 10; $i++){ echo $_POST[$i] . '<br />'; } Or: foreach($_POST as $k => $v){ echo $k . ' = ' . $v . '<br />'; } Link to comment https://forums.phpfreaks.com/topic/126323-getting-variable-_post/#findComment-653244 Share on other sites More sharing options...
Barand Posted September 29, 2008 Share Posted September 29, 2008 make the names "cordx[$teller]" and cordy[$teller]. To process the $_POST foreach ($_POST['cordx'] as $teller => $cordx) { $cordy = $_POST['cordy'][$teller]; // process cordx, cordy } Link to comment https://forums.phpfreaks.com/topic/126323-getting-variable-_post/#findComment-653247 Share on other sites More sharing options...
havik Posted September 29, 2008 Author Share Posted September 29, 2008 make the names "cordx[$teller]" and cordy[$teller]. To process the $_POST foreach ($_POST['cordx'] as $teller => $cordx) { $cordy = $_POST['cordy'][$teller]; // process cordx, cordy } can u explain it a bit more ? i'm not getting the point tnx Link to comment https://forums.phpfreaks.com/topic/126323-getting-variable-_post/#findComment-653277 Share on other sites More sharing options...
Barand Posted September 29, 2008 Share Posted September 29, 2008 Putting [$teller] after the name causes the fields to be posted as an array with $teller as the key. Run this sample script, it may help you to see what happens <?php if (isset($_POST['btnSubmit'])) { echo "<p>Posted data</p>"; echo '<pre>', print_r($_POST, true), '</pre>'; echo "<p>Processing posted data</p>"; foreach ($_POST['cordx'] as $teller => $cordx) { // get matching cordy $cordy = $_POST['cordy'][$teller]; echo "Teller $teller coords are $cordx, $cordy <br/>"; } exit; } echo '<form method="POST">'; $x = 10; $y = 100; for ($teller=1; $teller <= 3; $teller++) { // input fields for each teller echo "Teller $teller : X <input type='text' name='cordx[$teller]' value='$x' size='5'> Y <input type='text' name='cordy[$teller]' value='$y' size='5'> <br/>"; $x += 10; $y += 100; } echo "<input type='submit' name='btnSubmit' value='Submit'> "; echo '</form>'; ?> Link to comment https://forums.phpfreaks.com/topic/126323-getting-variable-_post/#findComment-653344 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.