Я новичок в codeigniter. Я пытаюсь вставить несколько новостей, содержащих некоторый флажок, где его значения зацикливаются из базы данных. Но я не знаю, что должен писать код для этого в контроллере и модели для вставки значений. Может ли кто-нибудь предложить или помочь мне написать код?
Вид (content.php)
<?php foreach($result as $aresult) { ?> <input type="checkbox" name="category_name[<?php echo $aresult->category_name; ?>]" value="<?php echo $aresult->category_name;?>" /> <?php echo $aresult->category_name;?> <br> <?php } foreach($area as $aresult1) { ?> <input type="checkbox" name="category_name[<?php echo $aresult->category_name; ?>]" value="<?php echo $aresult1->category_name;?>" /> <?php echo $aresult1->category_name;?> <br> <?php } ?> <tr> <td> <input type="text" required="1" name="content_headline" tabindex="3" placeholder="Content Headline" size="80"/> </tr> </td> <tr> <td> <textarea name="content_shortdetails" tabindex="4" maxlength="145" placeholder="Content Short Details" rows="10" cols="78"></textarea> </tr> </td> <tr> <td>Picture</td> <td> <input type="file" name="image" tabindex="8"/> </td> </tr> <tr> <td>Publication Status:</td> <td> <input type="radio" name="publication_status" value="1" tabindex="3" />Publish <input type="radio" name="publication_status" value="0" tabindex="4" />Unpublish </td> </tr> <tr> <td> <input type="submit" name="btn" value="Save" tabindex="9"/></td> </tr> controller(content) : public function savecontent() { $data=array(); date_default_timezone_set('Asia/Dhaka'); $now = date("Ymd H:i:s"); $data['admin_id']=$this->session->userdata('admin_id'); $data['category_name']=$this->input->post('category_name',true); $data['content_headline']=$this->input->post('content_headline',true); $data['content_shortdetails']=$this->input->post('content_shortdetails',true); $data['publication_status']=$this->input->post('publication_status',true); $data['date_add']=$now; /* -------------Image Upload---------------- */ $this->load->library('upload'); $config['upload_path'] = './images/news_images/'; $config['allowed_types'] = 'gif|jpg|png|mp3'; $config['max_size'] = '100000'; $config['max_width'] = ''; $config['max_height'] = ''; $error = ''; $udata = ''; $this->upload->initialize($config); if (!$this->upload->do_upload('image')) { $error = array('error' => $this->upload->display_errors()); // echo '<pre>'; // print_r($error); //$this->load->view('upload_form', $error); } else { $udata = array('upload_data' => $this->upload->data()); $data['image'] = "images/news_images/" . $udata['upload_data']['file_name']; $this->load->view('upload_success', $data); } $this->co_model->save_content($data); } model(co_model) : public function save_content($data) { $this->db->insert('content',$data); }
Структура базы данных:
category { cat_id(auto incr.), category_name(varchar 50) } content { id(auto incr.), category_name(varchar 50), content_headline(varchar 50), shortdetails(varchar 50), publication_status(tinyint 1), date_add(datetime), image(varchar 255) } in view page category_name are come from category table where i already inserted some category name and then all news are inserted in content table. now what should i change to insert multiple row using checkbox ? when i insert one news it can be insert multiple category name(checkbox value) in multiple row in db with other value (other value not changed) . like: category name (checkbox) =c_1, c_3, c_4 { content headline = something shortdetails = again something mage = pic.jpg publication status = 1 (publish) }--> all this news item as same in all checked category