【问题标题】:how to store data into the database and generate the sum using codeigniter如何将数据存储到数据库中并使用 codeigniter 生成总和
【发布时间】:2020-09-02 06:26:18
【问题描述】:

我创建了这个表格,当我按下保存按钮时,每一行的计算数量将出现在 nilai 列中。我想将每一列存储在数据库中。

代码如下:

<?php foreach ($siswa as $row){
                    
                    echo "<tr>  <td width='100'>$row->nis</td>
                                <td>".  strtoupper($row->nama)."</td>
                                <td width='150'><input type='int' id='tugas_1".$row->nis."' value='".  chek_tugas1($row->nis, $this->uri->segment(3))."' class='form-control'></td>
                                <td width='150'><input type='int' id='tugas_2".$row->nis."' value='".  chek_tugas2($row->nis, $this->uri->segment(3))."' class='form-control'></td>
                                <td width='150'><input type='int' id='tugas_3".$row->nis."' value='".  chek_tugas3($row->nis, $this->uri->segment(3))."' class='form-control'></td>
                                <td width='150'><input type='int' id='tugas_4".$row->nis."' value='".  chek_tugas4($row->nis, $this->uri->segment(3))."' class='form-control'></td>
                                <td width='150'><input type='int' id='nilai_akhir".$row->nis."' value='' class='form-control'></td></tr>";
                }
            ?>

【问题讨论】:

  • 请注意,数据库表不是电子表格。认真考虑规范化您的架构。

标签: php mysql codeigniter


【解决方案1】:

如果保存按钮是表单提交事件,请考虑在服务器端进行操作。否则,只需在迭代中调用每个函数并将它们相加即可。

<?php foreach ($siswa as $row){
                    
                    echo "<tr>  <td width='100'>$row->nis</td>
                                <td>".  strtoupper($row->nama)."</td>
                                <td width='150'><input type='int' id='tugas_1".$row->nis."' value='".  chek_tugas1($row->nis, $this->uri->segment(3))."' class='form-control'></td>
                                <td width='150'><input type='int' id='tugas_2".$row->nis."' value='".  chek_tugas2($row->nis, $this->uri->segment(3))."' class='form-control'></td>
                                <td width='150'><input type='int' id='tugas_3".$row->nis."' value='".  chek_tugas3($row->nis, $this->uri->segment(3))."' class='form-control'></td>
                                <td width='150'><input type='int' id='tugas_4".$row->nis."' value='".  chek_tugas4($row->nis, $this->uri->segment(3))."' class='form-control'></td>
                                <td width='150'><input type='int' id='nilai_akhir".$row->nis."' value='".(chek_tugas1($row->nis, $this->uri->segment(3))+chek_tugas2($row->nis, $this->uri->segment(3))+chek_tugas3($row->nis, $this->uri->segment(3))+chek_tugas4($row->nis, $this->uri->segment(3)))."' class='form-control'></td></tr>";
                }
            ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 2015-04-29
    • 2011-10-29
    • 2012-07-31
    • 2021-02-27
    • 2016-05-18
    • 1970-01-01
    相关资源
    最近更新 更多