Welcome Guest, Not a member yet? Register   Sign In
Simple checkbox question with array insertion
#1

[eluser]Unknown[/eluser]
Hi I'm fairly new to all of this CodeIgniter stuff and so far is has been awesome! Now I have been following a few great tutorials but I have hit a small problem. I have successfully set up 7 checkboxes to store as an array however I'm at a loss on how to get said array into the database.

Here is my view:
Code:
<label for="services">Services Needed: <span id="emph">(select all that apply)</span></label>
                <br />
                &lt;?php $data = array (
                    'name' => 'services[]',
                    'id' => 'in_home_care',
                    'value' => 'in_home_care',
                    );
                echo form_checkbox($data,'', set_checkbox('services[]', 'in_home_care', FALSE)); ?&gt;
                <span style="position:relative;bottom:2px;font-size: 11px;">In-home Care</span>
                &lt;?php $data = array (
                    'name' => 'services[]',
                    'id' => 'assisted_living',
                    'value' => 'assisted_living',
                    );
                echo form_checkbox($data,'', set_checkbox('services[]', 'assisted_living', FALSE)); ?&gt;
                <span style="position:relative;bottom:2px;font-size: 11px;">Assisted Living</span>
                &lt;?php $data = array (
                    'name' => 'services[]',
                    'id' => 'nursing_home',
                    'value' => 'nursing_home',
                    );
                echo form_checkbox($data,'', set_checkbox('services[]', 'nursing_home', FALSE)); ?&gt;
                <span style="position:relative;bottom:2px;font-size: 11px;">Nursing Home</span>
                &lt;?php $data = array (
                    'name' => 'services[]',
                    'id' => 'medical_equipment',
                    'value' => 'medical_equipment',
                    );
                echo form_checkbox($data,'', set_checkbox('services[]', 'medical_equipment', FALSE)); ?&gt;
                <span style="position:relative;bottom:2px;font-size: 11px;">Medical Equipment</span>
                <br />
                &lt;?php $data = array (
                    'name' => 'services[]',
                    'id' => 'adult_day_care',
                    'value' => 'adult_day_care',
                    );
                echo form_checkbox($data,'', set_checkbox('services[]', 'adult_day_care', FALSE)); ?&gt;
                <span style="position:relative;bottom:2px;font-size: 11px;">Adult Daycare</span>
                &lt;?php $data = array (
                    'name' => 'services[]',
                    'id' => 'moving_services',
                    'value' => 'moving_services',
                    );
                echo form_checkbox($data,'', set_checkbox('services[]', 'moving_services', FALSE)); ?&gt;
                <span style="position:relative;bottom:2px;font-size: 11px;">Moving Services</span>
                &lt;?php $data = array (
                    'name' => 'services[]',
                    'id' => 'financial_planning',
                    'value' => 'financial_planning',
                    );
                echo form_checkbox($data,'', set_checkbox('services[]', 'financial_planning', FALSE)); ?&gt;
                <span style="position:relative;bottom:2px;font-size: 11px;">Financial Planning</span>

And my controller (with some functional code for inserting strings into the database to show you what I am up to):
Code:
$c = new Client();
        $c->first_name = $this->input->post('first_name');
        $c->last_name = $this->input->post('last_name');
        $c->email = $this->input->post('email');
        $c->phone = $this->input->post('phone');
        $c->other_phone = $this->input->post('other_phone');
        $c->city = $this->input->post('city');
        $c->state = $this->input->post('state');
      
        $c->in_home_care = $this->input->post('services');
        $c->assisted_living = $this->input->post('services');
        $c->nursing_home = $this->input->post('services');
        $c->medical_equipment = $this->input->post('services');
        $c->adult_day_care = $this->input->post('services');
        $c->moving_services = $this->input->post('services');
        $c->financial_planning = $this->input->post('services');
        $c->save();

        $this->load->view('submit_success');

Now those last 7 inputs are obviously incorrect but I left them that way so you can see the desired structure of the database.

Now a bit of searching has shown me I need to do some foreach loops but I'm at a loss where to start. A bit of guidance would be greatly appreciated as I am sure this is elementary!

-michael
#2

[eluser]Unknown[/eluser]
Doh. Looks like this was the wrong place to put this! I just followed a search engine here and everyone else had asked for help here too Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB