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; ?> Quote Link to comment Share on other sites More sharing options...
Solution kicken Posted June 11, 2013 Solution 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. } Quote Link to comment Share on other sites More sharing options...
alanl1 Posted June 11, 2013 Author Share Posted June 11, 2013 fantastic thankyou Quote Link to comment 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.