使用select2,如何使用CodeIgniter通过PHP获取多个数据?

Here is my view page. How can I add multiple data from here?

  <select multiple  id="e19">
      <option value="January">January</option>
      <option value="February">February</option>
      <option value="March">March</option>
      <option value="April">April</option>
      <option value="May">May</option>
      <option value="June">June</option>
      <option value="July">July</option>
      <option value="August">August</option>
      <option value="September">September</option>
      <option value="October">October</option>
      <option value="November">November</option>
      <option value="December">December</option>
</select>

You don't mantion the name of select tag which is mandatory.

Ok. Let the name of select tag is 'month' then your code will look like that

<select multiple id="e19" name="month[]">

Now in your controller you will get an array with selected item.

Let you have select 3 Item which are January, April and December

Now you print the $_POST['month']

Here I give an example in CI

echo '<pre>';
print_r($this->input->post('month'))
echo '</pre>';

Then your output will be look like that

array(
      '0' => 'January'
      '1' => 'April'
      '2' => 'December'
)

Now you can do with this array whatever you want.

If you write:

<form method="post">
<select multiple name="e19[]">

then $_POST['e19'] is an array that contains all the values selected by the user.

You should add a name attribute to the select element, and you will get the array selected options in PHP.

 <select multiple name="select[]" id="e19">
   <option value="January">January</option>
   <option value="February">February</option>
   <option value="March">March</option>
   <option value="April">April</option>
   <option value="May">May</option>
   <option value="June">June</option>
   <option value="July">July</option>
   <option value="August">August</option>
   <option value="September">September</option>
   <option value="October">October</option>
   <option value="November">November</option>
   <option value="December">December</option>
</select>

Access it from CodeIgniter:

$options = $this->input->post('select');
foreach($options as $option){
    echo $option;
}