ID选择php / jquery [关闭]

I have an select option like this :

    for($i = 1; $i <= 5; $i++)
    {
        $body .= <<<EOT

    <form method="GET" action="page2.php">
    <select class="multiSelect" size="7" name="opt[]" id="{$i}">
    <option value="1">1</option>
    <option value="2">2</option>
    ...
    </select>
    </form>
EOT;
    }

In the second page page2.php

if (isset($_GET['opt']) && !empty($_GET['opt']))
    {

        foreach($_GET['opt'] as $opt)
            $html .= "You have choice the option $opt in the !!!! $i !!!! select <br />
" ;

    }

I want to get the id ($i) of each select in the page2.php ? Can You help me please ? Thanks

I think what you want is this:

I moved the form tag out of the loop, so that all selects are included in one form, I then assigned a unique name to each form.

$body .= '<form method="GET" action="page2.php">';

for($i = 1; $i <= 5; $i++)
{
    $body .= <<<EOT
        <select class="multiSelect" size="7" name="opt_$i[]" id="{$i}">
        <option value="1">1</option>
        <option value="2">2</option>
        ...
        </select>

EOT;
}
$body.= '</form>';

and on page2 you want to do something like this: here I use 2 loops, the first one is looping through your selects (I'm assuming you always have 5 selects), I generate the name of each form with opt_$i (will be opt_1 ... opt_5)

With the second loop, I loop through all selected values that where selected in that select

$html = 'your choices:<br/>';
for($i = 1; $i <= 5; $i++)
    $sel = "opt_$i";    
    $html.= "in Select $i you selected:";
    foreach($_GET[$sel] as $opt){
        $html.= $opt;
    }
}

you def. want to make the output prettier, but that should be easy to do and just adds more code, making it harder to see the essential steps.

if for whatever reason you want to keep your 5 forms: you could pass the id of the select as a get Param like this:

action="page2.php?selectId=$i"

and use $_GET['selectId'] to retrieve it on page2

if that is also not what you want please explain more clearly WHAT you want?