如何使用代码点火器在数据库中提交多行表格形式数据?

时间:2016-08-15 15:03:11

标签: php mysql forms codeigniter

您好我正在创建学校管理系统并面临一些问题。 问题是我有一个复杂的表单,其中包含表格中的以下字段

enter image description here

我有一个表费结构,我想在其中插入数据。

有列

id | classID | sectionID | feetypeID | must   | amount | active
 1       1         1           1       must      500       yes  
 2       1         1           2       optional  500       no

所以如何创建一个数组,以便它使用上面的表单在表中插入数据。 基本上我希望用户选择他们想要用于类的脚型并设置它们的数量,然后选择他们想要应用它的类,这样就可以在数据库中为每个部分和他们选择的每个脚型创建一个条目。

我不知道如何为此制作控制器和模型,但我有这个视图代码

查看

<form class="form-horizontal" role="form" method="post">
<div class="box-body">
<div class="row">

<div class="col-sm-12">

<h3>Fee Types</h3><br>
<div id="hide-table">

<table id="example1" class="table table-striped table-bordered table-hover dataTable no-footer">
    <thead>

        <tr>
<th class="col-sm-2"><?=$this->lang->line('slno')?></th>
<th class="col-sm-2"><?=$this->lang->line('feetype')?></th>
<th class="col-sm-2"><?=$this->lang->line('amount')?></th>   
<th class="col-sm-2"><?=$this->lang->line('must')?></th>
<th class="col-sm-2"><?=$this->lang->line('active')?></th>
<th class="col-sm-2"><input type="checkbox"> Select All</th>
</tr>
</thead>
<tbody>
<?php if(count($feetypes)) {$i = 1; foreach($feetypes as $feetype) { ?>
<tr>
<td data-title="<?=$this->lang->line('slno')?>">
<?php echo $i; ?>
</td>
<td data-title="<?=$this->lang->line('feetype_name')?>" name="feetypeID" value="<?php echo $feetype->feetypeID;?>">
<?php echo $feetype->feetype; ?>
</td>

<td data-title="<?=$this->lang->line('amount')?>" name="amount">
<input type="text" class="form-control" value="<?php echo $feetype->defaultamount; ?>">
</td>
<td data-title="<?=$this->lang->line('must')?>">
                                <select class="form-control" name="must">
                                <option value="MUST">Must</option>
                                <option value="OPTIONAL">Optional</option>
                                </select>

</td>
<td data-title="<?=$this->lang->line('active')?>">
                                <select class="form-control" name="active">
                                <option value="1">Yes</option>
                                <option value="0">No</option>
                                </select>

</td> 
                                <td data-title="<?=$this->lang->line('select')?>">
                                <input type="checkbox" name="selected">
</td>

</tr>
<?php $i++; }} ?>
</tbody>
</table>
</div>


            <div class="row">
            <div class="col-sm-8">
        <h3> Apply To</h3><br>
        </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
    <table class="table table-bordered table-striped">
<thead>
  <th class="col-sm-3">Class</th>
  <th class="col-sm-4">Section</th>
</thead>
<tbody> 
<?php 
foreach ($categories as $category)
    {
?>
<tr>
<td>   <input type="checkbox"><span style="font-size:18px;margin-left:10px;"> <?php echo $category->classes; ?></span>
</td>

<td>
<?php
if(!empty($category->subs)) { 

    foreach ($category->subs as $sub)  {
        echo  "<input type='checkbox'> ".$sub->section.'&nbsp;&nbsp;&nbsp;&nbsp;' ;
    }

}
?>
</td>
</tr>
<?php
    }
?>
</tbody>
    </table>
    <br><br>
                          <div class="form-group">
<div class="col-sm-12">
                           <input type="submit" class="btn btn-success" value="<?=$this->lang->line("add_feestructure")?>" >
    </div>
</div>
</div>




            </form>

控制器

public function addfeestructure(){
    $usertype = $this->session->userdata("usertype");
    if($usertype == "Admin" || $usertype == "Accountant"){
        $this->data['categories'] = $this->feestructure_m->get_categories();

        $this->data['feetypes'] = $this->feestructure_m->get_feetypes();
        if($_POST){

        }
        $this->data['subview'] = "feestructure/addfeestructure";
        $this->load->view('_layout_main', $this->data);
    }
}

0 个答案:

没有答案