我在用Jquery 多选小部件 http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/有一个带有多选选项的下拉列表框。我正在使用 MySql 数据库中的数据填充下拉列表。我无法将多个值传递到 $_POST 中的 php 文件。
我的多选下拉菜单的 HTML 和 PHP 代码。
<form id="intermediate" name="inputMachine" method="post">
<select id="selectDuration" name="selectDuration" multiple="multiple">
<option value="1 WEEK" >Last 1 Week</option>
<option value="2 WEEK" >Last 2 Week </option>
<option value="3 WEEK" >Last 3 Week</option>
</select>
<?php
//include '../db/interface/DB_Manager.php';
$connect = mysql_connect("localhost", "root", "infinit") or die(mysql_error());
mysql_select_db("serverapp") or die(mysql_error());
$query = "select id,name from rpt_shift_def"; //Write a query
$data = mysql_query($query); //Execute the query
?>
<select id="selectShift" name="selectShift" multiple="multiple">
<?php
while($fetch_options = mysql_fetch_array($data)) { //Loop all the options retrieved from the query
?>
<option name="selected_ids[]" id ="<?php echo $fetch_options['id']; ?>" value="<?php echo $fetch_options['name']; ?>"><?php echo $fetch_options['name']; ?></option><!--Echo out options-->
<?php
}
?>
</select>
在这里,我在多选下拉列表中填充 Shift 下拉列表。如果我选择多个班次,我将无法在 php.ini 中获取所有选定的值。相反,我只得到最后选择的值。
我想做这样的事情。
$shiftarraycalc = array();
foreach ($_POST['selectShift'] as $key => $value) {
array_push($shiftarraycalc,$value);
}
但它不起作用。
我不知道如何在 $_POST 中获取多个值。
将名称修改为 select 中的数组
<select id="selectShift" name="selectShift[]" multiple="multiple">
并这样做了并且它有效
$shiftarraycalc = array();
$shift=$_POST['selectShift'];
if ($shift)
{
foreach ($shift as $value)
{
array_push($shiftarraycalc,$value);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)