2015-12-24 75 views
0

這裏我想用post方法捕獲數組值。任何人都可以幫助我,我到底錯在哪裏?多選擇捕獲,發佈方法

<html> 
    <body> 
     <form action="test1.php" method="post"> 
     <ul> 
      <li class="fltlft newDesgnCal" style="margin-left:0px;margin-top:0px"> 
       <select id="filterCal" multiple="multiple" name="it_budget[]"> 
        <option value="0-50" <?php if((isset($_POST["it_budget"][0])) && ($_POST["it_budget"][0] == '0-50')){?> selected <?php } ?>>&euro;0-&euro;50Mn</option> 
        <option value="50-100" <?php if((isset($_POST["it_budget"][0]) == '50-100' || isset($_POST["it_budget"][1]) == '50-100')){?> selected <?php } ?>>&euro;50-&euro;100Mn</option> 
        <option value="100-1150" <?php if((isset($_POST["it_budget"][0]) == '100-1150' || isset($_POST["it_budget"][1]) == '100-1150' || isset($_POST["it_budget"][2]) == '100-1150')){?> selected <?php } ?>>>&euro;100Mn</option> 
       </select> 
      </li> 
     </ul> 
     </td> 
     <td> 
      <ul> 
       <li class="fltlft newDesgnCal" style="margin-left:0px;margin-top:0px"> 
        <select id="filterCal" multiple="multiple" name="Contract_Size[]"> 
        <option value="0-25" <?php if(isset($_POST["Contract_Size"][0]) && ($_POST["Contract_Size"][0] == '0-25')){?> selected <?php } ?>>&euro;0-&euro;25Mn</option> 
        <option value="25-50" <?php if(isset($_POST["Contract_Size"][0]) || isset($_POST["Contract_Size"][1]) && ($_POST["Contract_Size"][0] == '25-50' || $_POST["Contract_Size"][1] == '25-50')){?> selected <?php } ?>>&euro;25-&euro;50Mn</option> 
        <option value="50-100" <?php if(isset($_POST["Contract_Size"][0]) || isset($_POST["Contract_Size"][1]) || isset($_POST["Contract_Size"][2]) && ($_POST["Contract_Size"][0] == '50-100' || $_POST["Contract_Size"][1] == '50-100' || $_POST["Contract_Size"][2] == '50-100') ){?> selected <?php } ?>>&euro;50-&euro;100Mn</option> 
        <option value="100-300" <?php if(isset($_POST["Contract_Size"][0]) || isset($_POST["Contract_Size"][1]) || isset($_POST["Contract_Size"][2]) || isset($_POST["Contract_Size"][3]) && ($_POST["Contract_Size"][0] == '100-300' || $_POST["Contract_Size"][1] == '100-300' || $_POST["Contract_Size"][2] == '100-300' || $_POST["Contract_Size"][3] == '100-300') ){?> selected <?php } ?>>&euro;100-&euro;300Mn</option> 
        <option value="300-10000" <?php if(isset($_POST["Contract_Size"][0]) || isset($_POST["Contract_Size"][1]) || isset($_POST["Contract_Size"][2]) || isset($_POST["Contract_Size"][3]) || isset($_POST["Contract_Size"][4]) && ($_POST["Contract_Size"][0] == '300-10000' || $_POST["Contract_Size"][1] == '300-10000' || $_POST["Contract_Size"][2] == '300-10000' || $_POST["Contract_Size"][3] == '300-10000' || $_POST["Contract_Size"][3] == '300-10000') ){?> selected <?php } ?>>>&euro;300Mn</option> 
        </select> 
       </li> 
      </ul> 
      <input type="submit"/> 
     </form> 
    </body> 
</html> 
</ul> 

回答

1

試試這個:

使用foreach循環itrate所有數組元素與期權價值進行檢查。如果它匹配,則返回break循環。

<select id="filterCal" multiple="multiple" name="it_budget[]"> 
    <option value="0-50" <?php foreach($_POST['it_budget'] as $b) { if($b == "0-50") { echo "selected='selected'"; break; } } ?> >&euro;0-&euro;50Mn</option> 
    <option value="50-100" <?php foreach($_POST['it_budget'] as $b) { if($b == "50-100") { echo "selected='selected'"; break; } } ?> >&euro;50-&euro;100Mn</option> 
    <option value="100-1150" <?php foreach($_POST['it_budget'] as $b) { if($b == "100-1150") { echo "selected='selected'"; break; } } ?> >&euro;100Mn</option> 
</select> 
+0

它說: 「警告:\ XAMPP \ htdocs中\ oppInsights \ test1.php第7行>€0-€50MN:在提供的foreach()無效參數」 – 3bu1