alanl1 Posted June 10, 2013 Share Posted June 10, 2013 I have a lot of dropdown boxes that I am echoing out as shown below is there a way to echo out as many as the previous page contains as they are created dynamically from spreadsheets so there could be one dropdown box or many dropdown boxes <?php$secondDropbox0 = $_POST['secondDD0'];$secondDropbox1 = $_POST['secondDD1'];$secondDropbox2 = $_POST['secondDD2'];$secondDropbox3 = $_POST['secondDD3'];$secondDropbox4 = $_POST['secondDD4']; $thirdDropbox0 = $_POST['thirdDD0'];$initialDropbox0 = $_POST['dropdown0']; echo "the inital dropdown box value is equal to " . $initialDropbox0; ?><br><?phpecho "the seconds first dropdown box value is equal to " . $secondDropbox0; ?><br><?phpecho "the seconds second dropdown box value is equal to " . $secondDropbox1; ?><br><?phpecho "the seconds third dropdown box value is equal to " . $secondDropbox2; ?><br><?phpecho "the seconds fourth dropdown box value is equal to " . $secondDropbox3; ?><br><?phpecho "the seconds fifth dropdown box value is equal to " . $secondDropbox4; ?><br><?phpecho "the thirds 1st dropdown box value is equal to " . $thirdDropbox0; ?> Link to comment https://forums.phpfreaks.com/topic/279018-retrieving-values-through-_post/ Share on other sites More sharing options...
kicken Posted June 11, 2013 Share Posted June 11, 2013 Name them as an array rather than a numerical sequence. Then you can do a simple foreach loop over them. On the previous page: <select name="secondDD[]"> ... </select> <select name="secondDD[]"> ... </select> Then on the PHP processing side: foreach ($_POST['secondDD'] as $boxIndex=>$boxValue){ //$boxIndex is the box number: 0, 1, 2, 3 etc... //$boxValue is the selected option's value. } Link to comment https://forums.phpfreaks.com/topic/279018-retrieving-values-through-_post/#findComment-1435239 Share on other sites More sharing options...
alanl1 Posted June 11, 2013 Author Share Posted June 11, 2013 fantastic thankyou Link to comment https://forums.phpfreaks.com/topic/279018-retrieving-values-through-_post/#findComment-1435257 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.