Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This is my checkbox value in view :

$data = array(
'name'        => 'gejala[]',
'value'       => $row->id_gejala.",".$row->id_penyakit,
'checked'     => FALSE,
'style'       => 'margin:10px',
);

and next this is my controller :

function step2(){

        $a = implode(',',$this->input->post('gejala'));

        $break = explode(',',$a);



        $data = array(

            'id_gejala'=> $break[0],

            'id_penyakit'=>$break[1]

        );



        foreach($data as $penyakit){

            $data[] = array('id_gejala'=> $break[0],'id_penyakit'=>$break[1]);

        }

        print_r($data);

    }

Example result in my browser :

Array ( [id_gejala] => 58 [id_penyakit] => 6  )

My question, how to insert the result to database ? Maybe it look like here :

++++++++++++++++++++++++++++
id + id_gejala + id_penyakit
++++++++++++++++++++++++++++
1  +     58    +     6     +
share|improve this question

1 Answer

In your controller you need to write

$this->insert_model->insert($data);

In the insert_model you need to insert the data in that form:

class Insert_model extends CI_Model { // Name just for example
    function Insert_model() {
        parent:: __construct();

    }


    function insert($data) {
        $this->db->insert('table_name', $data); // Write the name of table
    }

}

If you have any problem, just tell me in comment. Thanks

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.