dtebrq0245 2014-05-08 09:19
浏览 47

MVC从复选框中插入数据库中的多个项目

View:

<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>

CONTROLLER:

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! One value is from an option button and the other value is from check box. so same value for the first input but different for the other. How will i insert it in the one table from two different database.

  • 写回答

1条回答 默认 最新

  • dou4381 2014-05-08 09:30
    关注

    you can define your checkbox as array

    <?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>";
                }
    

    ?>

    and on your controller

    foreach($name as $key=>$value)
    {
     $success = $this->some_model->insertPerson($value,$cname[$key]);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c