使用php中的create table创建数组数据

时间:2017-09-06 08:52:46

标签: php arrays

**我喜欢这个数组。我希望使用此数组创建table 1。我希望用于此PHP。如何使用数组数据创建表。 **

Array([1] => Array([STUDENT_ID] => 200301
                   [SUBJECT_NAME] => maths
                   [ASSIGNMENT_TITLE] => exam_1
                   [MARKS] => 25 )
      [2] => Array([STUDENT_ID] => 200301
                   [SUBJECT_NAME] => maths
                   [ASSIGNMENT_TITLE] => exam_2
                   [MARKS] => 45 )
      [3] => Array([STUDENT_ID] => 200301
                   [SUBJECT_NAME] => art
                   [ASSIGNMENT_TITLE] => exam_1
                   [MARKS] => 76 )
      [4] => Array([STUDENT_ID] => 200301
                   [SUBJECT_NAME] => art
                   [ASSIGNMENT_TITLE] => exam_2
                   [MARKS] => 42 )
      [5] => Array([STUDENT_ID] => 200302
                   [SUBJECT_NAME] => maths
                   [ASSIGNMENT_TITLE] => exam_1
                   [MARKS] => 71 )
      [6] => Array([STUDENT_ID] => 200302
                   [SUBJECT_NAME] => maths
                   [ASSIGNMENT_TITLE] => exam_2
                   [MARKS] => 78 )
      [7] => Array([STUDENT_ID] => 200302
                   [SUBJECT_NAME] => art
                   [ASSIGNMENT_TITLE] => exam_1
                   [MARKS] => 35 )
      [8] => Array([STUDENT_ID] => 200302
                   [SUBJECT_NAME] => art
                   [ASSIGNMENT_TITLE] => exam_2
                   [MARKS] => 61 )
     )

表1

这是我想要的创建表。如何使用数组数据创建此表。

|-------+------------+-----------------+-----------------+
|       |            |     maths       |      art        |  
|Seq No | Student Id |-----------------|-----------------|
|       |            | Exam 1 | Exam 2 | Exam 1 | Exam 2 |
|-------+------------+-----------------+-----------------+
|  1    | 200301     |   25   |   45   |  76    |  42    |
|  2    | 200302     |   71   |   78   |  35    |  61    |
|-------+------------+--------+--------+--------+--------|

我试过这个代码。但这不能正常工作。

$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 个答案:

没有答案