Welcome Guest, Not a member yet? Register   Sign In
Populate form_multiselect from SET values ?
#1

Hi guys,

I have a simple table  and one of the columns is   SET type (mariadb) . I have found this
way to insert values when adding records to the table (with a default selected value):

In my View Add Form:

PHP Code:
echo form_label('Select Department''Department');
$dept = array(
                  'DPT1' => '1',
                  'DPT2' => '2',
                  'DPT3' => '3',
                  'DPT4' => '4',
                  'DPT5' => '5',
                  'DPT6' => '6');
                  $sdept = array('1');
                  echo form_multiselect('Department[]'$dept$sdept); 

At first there was a bit of a struggle to understand that I needed  to convert the array from _POST
data to a string to insert into mariadb with something like that in my model :


PHP Code:
$dept $this->input->post('Department');

$data = array(
            'id' => $this->input->post('id'),
            'date' => $this->input->post('date'),
            'No' => $this->input->post('No'),
            'Act' => $this->input->post('Act'),
            'Category' => $this->input->post('Category'),
            'Department' => implode(",",$dept),
            // 'Department' => $this->input->post('Department'),
            'Desc' => $this->input->post('Desc'),
            'Remarks' => $this->input->post('Remarks'),
        );
        return $this->db->insert('Near'$data); 


Now I'm struggling on how to do the same when editing a record , how can I get the current values from the database SET and present them as a form_multiselect on my edit form ? is that even a possibility  ?

Thanks
Reply


Messages In This Thread
Populate form_multiselect from SET values ? - by stepgr - 01-19-2021, 03:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB