将多个选择选项存储到PHP数组中

时间:2021-01-26 15:42:09

I have an selectbox list Is it possible to select multiple option:

我有一个选择框列表是否可以选择多个选项:

<select name="access_list[ ]" size="7" multiple="multiple">
<?php $res=mysql_query("select * from list" ,$conn);
while($row=mysql_fetch_assoc($res))
echo"<option value=".$row['id'].">".$row['name']."</option>";?>
</select>

How do the values ​​that will be selected (select multiple values ​​together) can be stored in the array. I think that will do it for each order?

如何选择的值(一起选择多个值)可以存储在数组中。我想这会为每个订单做吗?

3 个解决方案

#1


12  

Use name as name="access_list[]" without space.

使用name作为name =“access_list []”,不含空格。

And you can get selected options with $_POST['access_list']

您可以使用$ _POST ['access_list']获取所选选项

$_POST['access_list'] is array that contains selected options

$ _POST ['access_list']是包含所选选项的数组

#2


3  

Replace your select tag with this:

用以下内容替换您的选择标记:

<select name="access_list[]" size="7" multiple="multiple">

If you want to get the array, you can do it like this:

如果你想获得数组,你可以这样做:

$data = $_POST['access_list'];
print_r($data);

#3


0  

store as array then in your php is like this.

存储为数组,然后在你的PHP就像这样。

<?php

    $access_list = $_POST['access_list'];

    foreach($access_list as $value)
    {
        //Do your code Here
    }


?>

#1


12  

Use name as name="access_list[]" without space.

使用name作为name =“access_list []”,不含空格。

And you can get selected options with $_POST['access_list']

您可以使用$ _POST ['access_list']获取所选选项

$_POST['access_list'] is array that contains selected options

$ _POST ['access_list']是包含所选选项的数组

#2


3  

Replace your select tag with this:

用以下内容替换您的选择标记:

<select name="access_list[]" size="7" multiple="multiple">

If you want to get the array, you can do it like this:

如果你想获得数组,你可以这样做:

$data = $_POST['access_list'];
print_r($data);

#3


0  

store as array then in your php is like this.

存储为数组,然后在你的PHP就像这样。

<?php

    $access_list = $_POST['access_list'];

    foreach($access_list as $value)
    {
        //Do your code Here
    }


?>