2016-04-27 69 views
0

我正在构建一个页面,其中有2个选择框。我将项目添加到选择#1中的选择#2。从选择通过POST获取所有选项

当点击提交按钮时,我想只从选择#2中获得所有选项,而不管它们是否被选中。

<?php 
require('handlers/handler.php'); 
$active = $_POST['activeProperties']; 
$slider = $_POST['sliderProperties']; 
$array = array(); 
if(isset($_POST['submit'])){ 
    if(isset($_POST['sliderProperties'])){ 
     foreach($_POST['sliderProperties'] as $item){ 
      $array[] = $item; 
     } 
    } 
    echo "<pre>"; 
    print_r($array); 
    echo "</pre>"; 
} 
?> 

<form method="post" style="height: 600px;"> 
      <select id="source" name="activeProperties[]" data-text="Source list" data-search="Search for options" style="height: 600px;"> 
       <?php 
       $query = $handler11->query("SELECT ID, name FROM properties WHERE active = 'yes' "); 
       while($row = $query->fetch()){ 
        echo '<option value="'.$row['ID'].'">'.$row['name'].'</option>'; 
       } 
       ?> 
      </select> 
      <select id="destination" name="sliderProperties[]" data-text="Destination list" data-search="Search for options"> 
      </select> 
      <input type="submit" name="submit" class="btn btn-primary" value="Save"/> 
    </form> 

我只使用此代码获取选择框中的第一项。我如何获得所有物品?

+0

您没有选择'F。 eld1'或者你需要使用'$ row ['name']'取决于哪一个是真的 – Mihai

+0

这是一个错误的抱歉......第一个选择正在从数据库填充。我怎样才能从目的地获得所有选项选择他们是否被选中? – BRG

回答

2

您可以使用多个选择HTML的(文件here ),试试这个:

<form method="post" style="height: 600px;"> 
    <select multiple id="source" name="activeProperties[]" data-text="Source list" data-search="Search for options" style="height: 600px;"> 
     <?php 
      $query = $handler11->query("SELECT ID, name FROM properties WHERE active = 'yes' "); 
      while($row = $query->fetch()){ 
       echo '<option value="'.$row['ID'].'">'.$row['name'].'</option>'; 
      } 
     ?> 
    </select> 
</form> 

另一种选择是通过JavaScript做

1

如果你想把所有的数据,如果选择或不,不能,你通过这个查询得到同样的结果在你的PHP:

$query = $handler11->query("SELECT ID, name FROM properties WHERE active = 'yes');

+0

我将所有数据传递到目的地选择 – BRG