I wonder if there's a way of setting multiple (say 3) values 'selected' in form_multiselect().
I got it working with only 1 value using key($selectie) where $selectie
is my query to get the values form the database for a specific company id.
My model query looks like this:
function getselection($id2)
{
$this->db->from('bedrijfcategorieen');
$this->db->join('categorieen', 'bedrijfcategorieen.idcategorieen = categorieen.idcategorieen');
$this->db->where('bedrijfcategorieen.idbedrijven', $id2);
$query = $this->db->get();
return $query->result_array();
}
My controller:
$data['selected'] = $this->members_model->getselection($id2);
My views:
<?php
foreach($selected as $row){
$selectie[$row['idcategorieen']] = $row['Categorie'];
}
echo '<pre>';
print_r($selectie);
echo '</pre>';
?>
<tr>
<td><?= form_label('Categorieen'); ?></td>
<td><?= form_multiselect('categorieen[]', $opties, key($selectie)); ?></td>
</tr>
print_r($selectie); produces:
Array
(
[11] => Webdesign
[12] => Vlaggen
[13] => Auto-s
)
or
Change your view like this
you make it like this:
it works for me on my multi select