创建带有PHP的表,并使用前值和当前值(数组)进行检查 [英] Create table with PHP checking with before value and current value (Array)

查看:52
本文介绍了创建带有PHP的表,并使用前值和当前值(数组)进行检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的数据表1.我希望将此表更改为table2.我必须为此使用PHP.我使用foreach编写了一些代码,但是无法正常工作. C

This is my data table1. I want this table change to as a table2. I have to use PHP for this. I wrote the some code using foreach but that is not working properly. C

表1

|-------+------------+--------------+---------+--------|
|Seq No | Student Id | Subject Name |  Exams  | Marks  |
|-------+------------+--------------+---------+--------|
|  1    | 200301     |   maths      |  Exam 1 |  25    |
|  2    | 200301     |   maths      |  Exam 2 |  45    |
|  3    | 200301     |   art        |  Exam 1 |  76    |
|  4    | 200301     |   art        |  Exam 2 |  42    |
|  5    | 200302     |   maths      |  Exam 1 |  71    |
|  6    | 200302     |   maths      |  Exam 2 |  78    |
|  7    | 200302     |   art        |  Exam 1 |  35    |
|  8    | 200302     |   art        |  Exam 2 |  61    |
|-------+------------+--------------+---------+--------|

我想使用PHP创建类似于table2的代码.

I want to create like table2 using PHP.

表2

|-------+------------+-----------------+-----------------+
|       |            |     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    |
|-------+------------+--------+--------+--------+--------|

**我写了一些这样的东西.但这不能正常工作. **

**I wrote some like this. but this is not working properly. **

$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>";

这是我的数组

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 )
 )

这是我的阵列数据.我必须使用此数组创建像table2一样的格式.任何人都可以帮助我.

This is my array data. I have to create like table2 using this array. any one can help me.

推荐答案

在我看来,您使用的表结构不正确.

It seems to me that the table structure you are using is incorrect.

这是您要查找的表布局的正确表结构.

Here is a correct table structure of the table layout you are looking for.

<table border=1>
    <thead>
        <tr>
            <th rowspan="2">Seq N0</th>
            <th rowspan="2">Student Id</th>
            <th colspan="2">maths</th>
            <th colspan="2">art</th>
        </tr>
        <tr>
            <td>Exam 1</td>
            <td>Exam 2</td>
            <td>Exam 1</td>
            <td>Exam 2</td>  
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>1</td>
            <td>82</td>
            <td>90</td>
            <td>60</td>
            <td>82</td>
        </tr>
        <tr>
            <td>1</td>
            <td>1</td>
            <td>82</td>
            <td>90</td>
            <td>60</td>
            <td>82</td>
        </tr>
    </tbody>
</table>

这篇关于创建带有PHP的表,并使用前值和当前值(数组)进行检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆