使用PHP检查创建表,使用之前的值和当前值

时间:2017-09-01 07:42:40

标签: php html mysql

这是我的数据表1。我希望这个表更改为table2。我必须使用PHP。我写了一些 代码使用foreach但是工作不正常。 ç

表1

    |-------+------------+--------------+--------+--------|
    |Seq No | Student Id | Subject Name | Exam 1 | Exam 2 |
    |-------+------------+--------------+--------+--------|
    |  1    | 200301     |   maths      |  51    |  25    |
    |  2    | 200301     |   art        |  64    |  45    |
    |  3    | 200302     |   maths      |  47    |  76    |
    |  4    | 200302     |   art        |  35    |  42    |
    |  5    | 200303     |   maths      |  65    |  71    |
    |  6    | 200303     |   art        |  48    |  78    |
    |-------+------------+--------------+--------+--------|

表2

|-------+------------+-----------------+-----------------+
|       |            |     maths       |      art        |  
|Seq No | Student Id |-----------------|-----------------|
|       |            | Exam 1 | Exam 2 | Exam 1 | Exam 2 |
|-------+------------+-----------------+-----------------+
|  1    | 200301     |   51   |   25   |  64    |  45    |
|  2    | 200302     |   47   |   76   |  35    |  42    |
|  3    | 200303     |   65   |   71   |  48    |  78    |
|-------+------------+--------+--------+--------+--------|

我想将数据表创建为“table2”

$output .= "<table border=1>
          <tr bgcolor=#ffffff><td>SeqNo</td>
          <td>Student Id</td>
          <td>maths</td>
          <td>art</td>
          <td>Exam 1</td>
          <td>Exam 2</td></tr>";

          $studentCounter = 0;

foreach($result as $item)
            {
            $output .= "<tr><td>" . ++$studentCounter . " </td>  
                                        <td>" . $item[STUDENT_ID] . "</td>
                                        <td>" . $item[MATHS] . "</td> 
                                        <td>" . $item[ART] . "</td>
                                        <td>" . $item[EXAM_1] . "</td>
                                        <td>" . $item[EXAM_2] . "</td></tr>";

            }
 $output .= "</table>";

0 个答案:

没有答案