drinksbreak Posted May 21, 2007 Share Posted May 21, 2007 Hi Guys Maybe you can help. Im working with an array in my php script and need to pass the entire array through a form. Here is the script. Take a look and tell me if you can see my mistake. I create a dynamic entry screen that has multiple values that I would like to update and want to place them all into an array to update them. At the mo no values are being posted at all. EG: Entry screen ****START FROM***** Update (product1) [ VALUE ] Update (product2) [ VALUE ] Update (product2) [ VALUE ] Update All ****** END FORM ************** Thanks in advance *****POST SCRIPT******************** $trans = array(); for($i = 0; $i < $rowz ; $i++) { $trans[] = $_POST['max_value[]']; } foreach($trans as $view) { echo "LETS TRY AGAIN : $view <br>"; } ************UPDATE SCRIPT****************** Have not written this yet until I see that all the correct values are being passed through the array. ***********************OUTSIDE FORM**************************************** $max_value = array(); **********************INSIDE FORM************************ for ($i=0; $i <$num_results; $i++) { <input type="text" name="<? echo "max_value[$i]"; ?>" value="<? echo "$cur_markup"; ?>"> } Thank You Quote Link to comment https://forums.phpfreaks.com/topic/52303-solved-php-array/ Share on other sites More sharing options...
akitchin Posted May 21, 2007 Share Posted May 21, 2007 your $_POST array notation is off - when you name an input as an array, it actually forms an array in the $_POST data: $_POST['max_value'][0] => the value from the first input named 'max_value[]' i haven't analysed your whole block of code, but i trust that's where the issue lies. just run a foreach() on $_POST['max_value'] to grab all the values entered. Quote Link to comment https://forums.phpfreaks.com/topic/52303-solved-php-array/#findComment-258039 Share on other sites More sharing options...
drinksbreak Posted May 21, 2007 Author Share Posted May 21, 2007 You can try this: **********************INSIDE FORM************************ for ($i=0; $i <$num_results; $i++) { <input type="text" name="array_values[<? echo "$max_value[$i]"; ?>]" value="<? echo "$cur_markup"; ?>"> } so that the name parameter will be "array_values[0]", "array_values[1]", "array_values[2]", ens. Where for example ids is: 0 => Hardware 1 => Software 2 => Consumables Let's say the values you input for the form is: 0 => 5 1 => 6 2 => 8 Then when you get the the Post value it will be "$_POST['array_values']" which will already be an array, so if you want to set it equal to another empty value just say: $the_array = $_POST['array_values']; When go through the array with: foreach ($the_array as $key => $value) { echo "$key => $value <br>"; } You'll get the result of: 0 => 5 1 => 6 2 => 8 Quote Link to comment https://forums.phpfreaks.com/topic/52303-solved-php-array/#findComment-258104 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.