drbfxb977777 2015-07-08 10:06
浏览 31

CI:将隐藏字段中的值保存到另一个表中

I created a form in CI framework with 60 fields, and the database works. now I want to separate some fields and send it to another table, which linked to primary table (with relatioship, of course). so I hide some fields, and show it if the radio button checked as "yes" :

<!-- other fields -->
<div><label class="control-label" for="imp_status">3rd Party</label>
 <div class="controls">
  <table>
   <tr>
    <td><input type="radio" name="imp_status" id="imp_status_yes" value="1" onclick="javascript:importirCheck()"> Yes</td>
    <td><input type="radio" name="imp_status" id="imp_status_no" value="0" onclick="javascript:importirCheck()"> No</td>
   </tr>
  </table>
 </div>
</div>
<div style="display:none" id="info_imp">
 <fieldset> somefields </fieldset>
</div>
<!-- other fields -->

script :

function importirCheck() {
    if (document.getElementById('imp_status_no').checked) {
        document.getElementById('info_imp').style.display = 'none';
        $("#imp_status_no").val("");
    }
    else {
        document.getElementById('info_imp').style.display = 'block';
        $("#imp_status_yes").val("");
        $("#imp_comp_name").val("");
        ...
    }
}

the view is working, but now I'm confused how I should get the value (especially from imp_status because there are 2 id) for my database. there's save button at the end of the form and it linked to another script. I sent other values from that script. now I have table_primary (.., imp_status, id_imp,..) and table_imp (id_imp,...). when there's no 3rd party, I want the imp_status column save "0" & set id_imp to NULL/0 (in table_primary). but if there's a 3rd party, imp_status column should save "1" & save all info about this 3rd party (to table_imp with primary key id_imp). is this the right way (for script)? how should I modify the model and controller? this is my current controller (no imp_status and id_imp yet):

...
$imp_comp_name=$this->input->post("imp_comp_name");
$this->form_m->set_imp_comp_name($imp_comp_name);
$imp_comp_dir=$this->input->post("imp_comp_dir");
$this->form_m->set_imp_comp_dir($imp_comp_dir);
...
$result = $this->form_m->insert();

and this is my current model :

// there are properties & setters
public function insert(){
   $sql = "INSERT INTO table_primary
          (...,imp_comp_name,...) VALUES (...,'".$this->imp_comp_name."',...)";
   return $this->db->query($sql);
}

I hope my question isn't confusing. links to read and learned are very welcomed, thanks.

  • 写回答

1条回答 默认 最新

  • duan0065626385 2015-07-08 11:38
    关注

    all though your question is little bit confusing but I am trying to give answer of it, you require further assist you can write back me with complete source code.

    first of all on server side , radio button value will be get by $imp_status=$this->input->post('imp_status'); and value will be value of selected radio button and according to that value of this radio button, you can update your database and create relation between two table.

    But in your query how you decide that there is third party in that form, please elaborate that to get more on it.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。