Serenitee Posted March 7, 2009 Share Posted March 7, 2009 Here is the situation: I have written a parser to go through a log file and pull out the info needed. This will produce specific items to match to the database which may come up with 1 or more results, returning the information into another form for the user to select which is appropriate (when more than one) or store the information in a hidden field (when there is only one). I created this form by counting the items then: foreach ($AllItems as $key => $value) {$fieldtally++; echo "<tr><th class=\"headTH\" colspan=\"2\">"; echo $key; echo "</th></tr>\n"; foreach ($value as $v) {$choices = count($value); if ($choices > "1") {if ($cssCt2 %2) {echo "<tr><td><input type=\"radio\" name=\"chosenItem$fieldtally\" value=\"($key) $v\"></td><td>$v</td></tr>\n";} else {echo "<tr><td class=\"one\"><input type=\"radio\" name=\"chosenItem$fieldtally\" value=\"($key) $v\"></td><td class=\"one\">$v</td></tr>\n";} $cssCt2++;} else {echo "<input type=\"hidden\" name=\"chosenItem$fieldtally\" value=\"($key) $v\">\n";} } } I now have (in this particular instance), 9 post data named chosenItem#. (ie: chosenItem1, chosenItem2, etc) Typically when wanting to use this information, I would set the variables: $chosenItem1 = $_POST['chosenItem1']; and so on. But as the amount of items (and there for 'chosen items') will vary every time, I would like to automate that and stick in an array - and this is where I am stuck. if ($formcount <= $totalDiffItems) {$formcount++; $chosenItems = array($_POST['chosenItem???']);} The ? ? ? is where I am stuck. I have tried just adding $formcount, as well as ".$formcount." in various formations and know there must be a way to do this as there will be many instances where the fields are auto-generating and of unknown number - alas I am unsuccessful in my search not having even a vague idea what it may be called. I'm sure someone else can explain much better, if I am completely confusing, please let me know how I can clarify. Any points in the proper direction would be appreciated. tia! Link to comment https://forums.phpfreaks.com/topic/148313-solved-name-values-in-formsretrieving-information-when-line-items-are-of-unknown/ Share on other sites More sharing options...
Serenitee Posted March 7, 2009 Author Share Posted March 7, 2009 while($formcount < $totalDiffItems) {$formcount++; $chosenItem = $_POST["chosenItem".$formcount.""]; $chosenItems[] = $chosenItem;} Found it on my own. Answer should anyone else need something like this - It may not be pretty, but it seems to work. Link to comment https://forums.phpfreaks.com/topic/148313-solved-name-values-in-formsretrieving-information-when-line-items-are-of-unknown/#findComment-778726 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.