查看:
<form action="<?php echo base_url(); ?>some_controller/insert" method="post">
<div id="choose app" style="width: 85%; height: 100px; overflow-y: scroll; padding:10px;">
<?php foreach($people as $row){
echo "<p><input type=radio name=name value=".$row->id."/>".$row->app_name."</p>";}
?>
</div>
</br>
2.) Choose Configuration Items
<a href ="">
<img src="<?php echo base_url(); ?>editButton.png" height=30 width=30 align=right hspace=5px>
</a>
<a href ="<?php echo base_url(); ?>some_controller/addCi_page">
<img src="<?php echo base_url(); ?>addButton.png" height=30 width=30 align=right hspace=5px>
</a>
<hr>
<div id="choose app" style="width: 85%; height: 350px; overflow-y: scroll; padding:10px;">
<?php
foreach($ciList as $row){
echo "<p><input type=checkbox name=cname value=".$row->affected_ci."/>".$row->affected_ci."</p>";
}
?>
</div>
<hr>
<center><input type="submit" value="SAVE"/></center>
</br>
控制器:
public function insert_page(){
$data['people'] = $this->some_model->getPeople();
$data['ciList'] = $this->some_model->getCI();
$this->load->view('templates/header.php', $data);
$this->load->view('templates/menu.php', $data);
$this->load->view('some_page/insert_page.php', $data);
$this->load->view('templates/footer.php');
}
public function insert(){
$this->load->model('some_model');
$name = $this->input->post('name');
$cname = $this->input->post('cname');
$success = $this->some_model->insertPerson($name,$cname);
if($success == TRUE)
$this->insert_page(TRUE);
else $this->insert_page(FALSE);
}
MODEL:
public function insertPerson($name,$cname){
$escName = $this->db->escape_str($name);
$eciName = $this->db->escape_str($cname);
$queryStr = "INSERT INTO appwarehouse.ci_table(app_id,ci_name) VALUES ('$escName','$eciName')";
$query = $this->db->query($queryStr);
return $query;
}
HELP!一个值来自选项按钮,另一个值来自复选框。第一个输入的值相同,但另一个输入的值不同。我将如何将它插入来自两个不同数据库的一个表中。
答案 0 :(得分:2)
您可以将复选框定义为数组
<?php foreach($people as $row){
echo "<p><input type=radio name=name[] value=".$row->id."/>".$row->app_name."</p>";}
?>
<?php
foreach($ciList as $row){
echo "<p><input type=checkbox name=cname[] value=".$row->affected_ci."/>".$row->affected_ci."</p>";
}
&GT;
并在你的控制器上
foreach($name as $key=>$value)
{
$success = $this->some_model->insertPerson($value,$cname[$key]);
}