Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

store multiple select option into a PHP array

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?

like image 497
vahid Avatar asked Jul 30 '13 21:07

vahid


3 Answers

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

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

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

like image 146
Bora Avatar answered Sep 28 '22 05:09

Bora


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);
like image 27
Erman Belegu Avatar answered Sep 28 '22 06:09

Erman Belegu


store as array then in your php is like this.

<?php

    $access_list = $_POST['access_list'];

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


?>
like image 36
Shaiful Ezani Avatar answered Sep 28 '22 05:09

Shaiful Ezani