插入每个学生的动态考试成绩

时间:2016-11-04 08:19:41

标签: php mysql arrays

我在将动态检查插入mysql数据库时遇到问题。 我不知道如何解释,所以这是我的代码:

我有表考试这是我的考试表结构:

考试表

+----+-----------+
| id | exam_name |
+----+-----------+
|  1 | run test  |
|  2 | swim test |
+----+-----------+

学生表:

+----+-------------+
| id |   student   |
+----+-------------+
|  1 | student one |
|  2 | student two |
+----+-------------+
问题是如何插入表格考试结果,例如学生一遍考试运行考试但游泳考试失败。因此,考试结果将显示如下:

+---------+------------+--------+
| id_exam | id_student | status |
+---------+------------+--------+
|       1 |          1 |      1 |
|       2 |          1 |      0 |
+---------+------------+--------+

这就是我如何将每一个考试和学生拿到html表格中以给出每个学生的结果:

<table class='wp-list-table widefat fixed striped posts'>
      <tr>
        <th class="bgth manage-column ss-list-width1">Participan Name</th>
          <th class="bgth manage-column ss-list-width1">Complited Pool Requirement</th>
          <th class="bgth manage-column ss-list-width1">Complited Theory Exam</th>
          <th class="bgth manage-column ss-list-width1">Medical Sertificate Checked</th>
    <th class="bgth manage-column ss-list-width" colspan="2">Action</th>
      </tr>
  <input type='hidden' name='exam_total' value='3'><input type='hidden' name='exam_names' value='[{"id":"1","exam_name":"Complited Pool Requirement"},{"id":"2","exam_name":"Complited Theory Exam"},{"id":"3","exam_name":"Medical Sertificate Checked"}]'><tr><td class='manage-column ss-list-width'>Handri angga riawan
        <input type='hidden' value='1' name='x-id[]'></td><td class='manage-column ss-list-width'>
          <input type='checkbox' name='Complited_Pool_Requirement[]' value='1'>check if pass
          <input type='hidden' name='id_exam[]' value='1' >
          </td><td class='manage-column ss-list-width'>
          <input type='checkbox' name='Complited_Theory_Exam[]' value='1'>check if pass
          <input type='hidden' name='id_exam[]' value='2' >
          </td><td class='manage-column ss-list-width'>
          <input type='checkbox' name='Medical_Sertificate_Checked[]' value='1'>check if pass
          <input type='hidden' name='id_exam[]' value='3' >
          </td><td class='manage-column ss-list-width'><a href='#'>Delete Participan</a></td></tr><td class='manage-column ss-list-width'>Suyadman
        <input type='hidden' value='2' name='x-id[]'></td><td class='manage-column ss-list-width'>
          <input type='checkbox' name='Complited_Pool_Requirement[]' value='1'>check if pass
          <input type='hidden' name='id_exam[]' value='1' >
          </td><td class='manage-column ss-list-width'>
          <input type='checkbox' name='Complited_Theory_Exam[]' value='1'>check if pass
          <input type='hidden' name='id_exam[]' value='2' >
          </td><td class='manage-column ss-list-width'>
          <input type='checkbox' name='Medical_Sertificate_Checked[]' value='1'>check if pass
          <input type='hidden' name='id_exam[]' value='3' >
          </td><td class='manage-column ss-list-width'><a href='#'>Delete Participan</a></td></tr></table><p><input type="submit" id="btn" name="p-submitted" value="Save Result"></p></form>

如何获得学生ID和他/她通过的所有考试,并且无法插入到mysql表格中,如下所示(考试成绩)

1 个答案:

答案 0 :(得分:0)

你的方法现在是正确的。像这样

&#13;
&#13;
| id_exam | id_student | status |
+---------+------------+--------+
|       1 |          1 |      1 |
|       2 |          1 |      0 |
+---------+------------+--------+
&#13;
&#13;
&#13;

你可以再添加一列结果(如得分)数据类型为float sot,它也允许你插入十进制值。

用于访问学生ID和考试ID以获取保存结果,然后只需在复选框中添加值&#34;检查是否通过&#34;在value属性中就像

一样
<input type="checkbox" value="exam_id#student_id"/>
邮政行动

将此值与#分开,您将获得考试ID和学生ID。

用于显示您的单选按钮,而不是像此一样的复选框

Select exam reslut
<input type="radio" name="swim_exam[]" value="exam_id#student_id#1"/> Pass
<input type="radio" name="swim_exam[]" value="exam_id#student_id#0"/> Fail

if you select pass you will get status 1 other wise get 0 with commonly exam and student id also.

所以它应该像下面的代码......

    <?php 
if(!empty($_POST['swim_exam'])){
        foreach($_POST['swim_exam'] as $swim_exam){
            $idnStatus = explode("#",$swim_exam);
            $examId = $idnStatus[0];
            $studentId = $idnStatus[1];
            $status = $idnStatus[2];

           // Your Insert query will perform here.... with all above id.
        }
    }
?>

试试这个。