0
我尝试写到哪,如果他们的价值可以在我的数据库中找到我的复选框的名单将被检查代码中找到勾选复选框,如果其值可以在数据库中使用笨
这是怎么了我的形式如下像
author name:______________
check the categories the author will handle
■ sports
■ comics
■ movies
■ ads
一次我去我的编辑作者页面,这是它应该如何看起来像
author name:Lorem
check the categories the author will handle
✓ sports
■ comics
✓ movies
■ ads
这是我的数据库看起来像
author.sql
UID auth_name
5 Lorem
6 Ipsum
7 Dolor
8 Sit
9 Amet
news.sql
UID title date
1 sports 1/1/2013
2 comics 2/2/2013
3 movies 3/3/2013
4 ads 4/4/2013
,这是我多么希望我的其他表看起来像一次提交我的形式
newscheckbox.sql
author_id newstitle_id checked
5 1 yes
6 1 yes
7 1 no
8 1 yes
9 1 no
这里是我的代码(这个代码的问题是它只插入那些带有检查的代码。所以我newscheckbox表看起来像这样)
newscheckbox.sql
author_id newstitle_id checked
5 1 yes
6 1 yes
8 1 yes
复选框没有插入到数据库中检查列不检查心不是
addauthor.php(图)
<?php
$attributes = array('class' => 'form form-horizontal','id'=>'form_auth','name'=>'form_auth');
echo form_open(base_url() . 'auth/submit_auth', $attributes);
?>
<input type="text" class="w300" name="auth_name" id="auth_name">
<?php
foreach($auth->result() as $a)
{
?>
<input type="checkbox" name="cats[]" value="<?php echo $a->UID; ?>"> DJ <?php echo $a->auth_name;?>
<?php
}
?>
</form>
控制器
public function auth_edit($id)
{
$data['auth'] = $this->jivecms_model->get_auth();
$data['news'] = $this->jivecms_model->get_news($id);
$data['id'] = $id;
$this->load->vars($data);
$this->load->view('auth/auth_edit');
}
public function submit_auth()
{
$this->jivecms_model->submit_auth();
redirect(base_url() . "auth/auth_edit");
}
模型
function submit_auth()
{
$auth_name = $this->input->post("auth_name");
$cats = $this->input->post("cats");
$newdata = array('auth_name'=>$auth_name
);
$this->db->insert('author', $newdata);
$id = $this->db->insert_id();
foreach($cats as $c)
{
if ($c == ""){$check="no";}
else{$check="yes";}
$auth = array('news_id'=>$c,'author_id'=>$id,'checked'=>$check);
$this->db->insert('newscheckbox', $auth);
}
}