0

I have been looking for this through the net but I have not found the right solution for my problem. I am working with the stock market. I have a form in my website, and a part of it needs to be repeated for some symbols.

Let's say I need to set some properties for each symbol, so I have some inputs that are the same for every symbol. What I would like to do is define the fields in some way that once I am processing them in my PHP script, I can access to the data doing something like this:

$_POST["symbol"]["field"]

I have 3 symbols now, but in the future I will have much more, so I would like to process the whole thing with a loop instead of having to access every single field manually (e.g.: $_POST["symbol-field"]).

The part of the code that it is repeated

<select multiple="multiple" name="selectAverageIBM[]">
    <option>SMA10</option>
    <option>SMA20</option>
    <option>EMA10</option>
    <option>EMA20</option>
</select>

So I already have an array for the field since it is a multiple select.

I have seen there is a tag called FIELDSET that could work, but I don't get it to work.

Thank you very much.

  • http://stackoverflow.com/questions/14026361/php-multiple-checkbox-array – Blazemonger Aug 21 '13 at 10:39
  • put more code for better solution – Sonu Sindhu Aug 21 '13 at 10:40
  • You can set the field names to `symbol[]`, which will cause their values to be handled as an array in PHP. Unfortunately, this method does not allow for further identification. The array will be a 0-indexed array, so you only have numeric array keys. – BenM Aug 21 '13 at 10:41
  • I have just added more code in the main message. I can not really use the symbol[] that you suggest BenM, since I already have it as an array because it is a multiple select. – user2417250 Aug 21 '13 at 10:47

1 Answers1

0

try this

set your field name as an array name="field[]" get it like this in php file

$field = $_POST[field];
    foreach($field as $value){
        // do stuff
    }

I hope it will help

Sonu Sindhu
  • 1,752
  • 15
  • 25