Saving articles_categories according to normalization
I have three tables
-----------
articles
-----------
id int(11)
title varchar(100)
-----------
categories
----------
id int(11)
title varchar(100)
-------------------
articles_categories
--------------------
articles_id int(11)
categories_id int(11)
I want to save it according to normalization rule to achieve like this
articles_id | categories_id
1 1
1 2
1 3
How can I achieve with code igniter thanks. So far I had already tried like this
View | Create.php
<?php echo form_input('title','','id="title_input"'); ?><br>
Category
<?php
foreach ($categories as $c)
{
echo '<input type="checkbox" id="categories[]" name="categories[]" value="'.$c['id'].'">';
echo $c['title'].' ';
}
?>
<?php
echo form_submit('Submit',"Submit");
echo form_close();
?>
Controller | articles.php
function insert()
{
$this->articles_model->save();
}
Model | articles_model.php
function save(){
$title=$this->input->post('title');
$categories= implode(',',$_POST['categories']); //inputs will be 1,2,3
$data=array(
/* missing ideas.............*/
);
$this->db->insert('articles_categories',$data);
}
Any help is appreciated. Thanks