bobohob Posted January 15, 2008 Share Posted January 15, 2008 I want to retrieve these value via "for" loop : $_POST['something_1'] $_POST['something_2'] $_POST['something_3'] $_POST['something_4'] $_POST['something_5'] How to do this ? Quote Link to comment https://forums.phpfreaks.com/topic/86107-solved-dynamic-name-_post/ Share on other sites More sharing options...
naveenbj Posted January 15, 2008 Share Posted January 15, 2008 Hello Im not sure but try this for($i=1;$i<=5;$i++) { echo $_POST['something[i]]; } Regards, nj Quote Link to comment https://forums.phpfreaks.com/topic/86107-solved-dynamic-name-_post/#findComment-439703 Share on other sites More sharing options...
bobohob Posted January 15, 2008 Author Share Posted January 15, 2008 thanks. but it doesn't work. the "something" is not array. Quote Link to comment https://forums.phpfreaks.com/topic/86107-solved-dynamic-name-_post/#findComment-439714 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 If you just copies naveebbj script and not learned how it work it wouldn't of worked. If you have studies for loops you would of spotted the problem. It should be for($i=1;$i<=5;$i++) { echo $_POST['something[$i]']; } Quote Link to comment https://forums.phpfreaks.com/topic/86107-solved-dynamic-name-_post/#findComment-439782 Share on other sites More sharing options...
rajivgonsalves Posted January 15, 2008 Share Posted January 15, 2008 well seeing what you want you should use a foreach loop foreach ($_POST as $strKey =>$strValue) { if (preg_match("/^something\_\d+/",$strKey)) { echo "$strkey - $strValue"; } } Quote Link to comment https://forums.phpfreaks.com/topic/86107-solved-dynamic-name-_post/#findComment-439786 Share on other sites More sharing options...
sasa Posted January 15, 2008 Share Posted January 15, 2008 try for($i=1;$i<=5;$i++) { echo $_POST["something_$i"]; } Quote Link to comment https://forums.phpfreaks.com/topic/86107-solved-dynamic-name-_post/#findComment-439856 Share on other sites More sharing options...
bobohob Posted January 16, 2008 Author Share Posted January 16, 2008 Thank you all. for($i=1;$i<=5;$i++) { echo $_POST["something_$i"]; } it works. Quote Link to comment https://forums.phpfreaks.com/topic/86107-solved-dynamic-name-_post/#findComment-440613 Share on other sites More sharing options...
cooldude832 Posted January 16, 2008 Share Posted January 16, 2008 just a thought, if you don't care about order make it an array i.e page 1 [code] <?php for ($i = 1; $i <= 10; $i++) { echo "<input type=\"text\" name=\"data[]\" value=\"\" />"; } ?> page 2 <?php if(is_array($_POST['data'])){ foreach($_POST['data'] as $value){ //work on the data } } ?> [/code] save you a lot of hassle about caring about the array's size Quote Link to comment https://forums.phpfreaks.com/topic/86107-solved-dynamic-name-_post/#findComment-440622 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.