i am novice in codeigniter. I am trying to insert multiple news that contains some check-box where its values are looped from a database. But i don't know what should code i write for this in controller & Model to insert values. can any one suggest or help me to write code?
view - content.php:
//category name
<?php foreach($result as $aresult) { ?>
<input type="checkbox" name="category_name[]" value="<?php echo $aresult->category_name;?>" /> <?php echo $aresult->category_name;?>
<?php } ?>
controller - news:
public function savecontent()
{
$data=array();
foreach($this->input->post('category_name') as $category_name)
{
$data[] = array('category_name' => $category_name);
}
$data['content_headline']=$this->input->post('content_headline',true);
$this->co_model->save_content($data);
}
Model:
public function save_content($data)
{
$this->db->insert('content',$data);
}
Database structure:
id(auto incr.), category_name(varchar 50), content_headline(varchar 100)
now what should i change to insert multiple row using checkbox ? here there have also another text box/column which also insert in database. but only category name(checkbox value) should be change for all value.