从多维数组创建多个HTML表

时间:2019-06-04 16:41:21

标签: php html codeigniter

我正在尝试从多维数组创建多个HTML表。我已经建立了一个数组,但是对如何将该数组转换为多个HTML表一无所知。

我想根据当天打开的时间和班级名称来分隔表格。

为了清楚起见,这是我的代码:

2 additional lines not shown
June 3rd 2019 13:49:27Info
/p:ENV_SETTINGS                "C:\Program Files (x86)\CorpCompany.BT.CorpProject\2.1.6\Deployment\EnvironmentSettings\Exporte... 
June 3rd 2019 13:49:27Info
/p:BTSACCOUNT                  CorpCompany\BizTalkAccount                                                                   
June 3rd 2019 13:49:27Info

June 3rd 2019 13:49:27Info
################################################################################### 
June 3rd 2019 13:49:27Info
Deploying BizTalk application CorpCompany.BT.CorpProject to the BizTalk console 
June 3rd 2019 13:49:27Info
################################################################################### 
June 3rd 2019 13:49:27Info

June 3rd 2019 13:49:27Info
Deploying biztalk app CorpCompany.BT.CorpProject ....... 
June 3rd 2019 13:49:27Info
Found shortcut for deploying app C:\ProgramData\Microsoft\Windows\Start Menu\Programs\CorpCompany.BT.CorpProject 1.0\Deploy CorpCompany.BT.CorpProject.lnk 
June 3rd 2019 13:49:27Info
Executing command ... cmd  /c @echo on & cd "C:\Program Files (x86)\CorpCompany.BT.CorpProject\2.1.6\\Deployment" & "C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" /p:Interactive=False  /t:Deploy /clp:NoSummary /nologo   /tv:4.0 Deployment.btdfproj /v:normal /p:DeployBizTalkMgmtDB=False /p:Configuration=Server  /p:ENV_SETTINGS="C:\Program Files (x86)\CorpCompany.BT.CorpProject\2.1.6\Deployment\EnvironmentSettings\Exported_ODSettings.xml" /p:BTSACCOUNT=CorpCompany\BizTalkAccount 
June 3rd 2019 13:49:28Info
Build started 6/3/2019 1:49:33 PM. 
June 3rd 2019 13:49:29Info
Project "C:\Program Files (x86)\CorpCompany.BT.CorpProject\2.1.6\Deployment\Deployment.btdfproj" on node 1 (Deploy target(s)). 
June 3rd 2019 13:49:29Info
C:\Program Files (x86)\CorpCompany.BT.CorpProject\2.1.6\Deployment\Framework\BizTalkDeploymentFramework.targets(635,5): error MSB4186: Invalid static method invocation syntax: "[Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToDotNetFramework(Microsoft.Build.Utilities.TargetDotNetFrameworkVersion.$(DotNetFrameworkVersion))". Must specify valid information for parsing in the string. Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(`a`, `b`)).  [C:\Program Files (x86)\CorpCompany.BT.CorpProject\2.1.6\Deployment\Deployment.btdfproj] 
June 3rd 2019 13:49:29Info
Done Building Project "C:\Program Files (x86)\CorpCompany.BT.CorpProject\2.1.6\Deployment\Deployment.btdfproj" (Deploy target(s)) -- FAILED. 
June 3rd 2019 13:49:29Info
Build FAILED. 
June 3rd 2019 13:49:29Info
Time Elapsed 00:00:00.20 
June 3rd 2019 13:49:29Info

June 3rd 2019 13:49:29Info
################################################################################### 
June 3rd 2019 13:49:29Info

June 3rd 2019 13:49:29Info
cmd completed with exit code 1 
June 3rd 2019 13:49:29Error
run-command : Script cmd failed. see log for errors 
June 3rd 2019 13:49:29Error
At C:\Octopus\Work\20190603204924-32036-322\Library_PublishBTDFBiztalkApplication_636951665673032401.psm1:734 char:9 
June 3rd 2019 13:49:29Error
+         run-command "cmd" $arg 
June 3rd 2019 13:49:29Error
+         ~~~~~~~~~~~~~~~~~~~~~~ 
June 3rd 2019 13:49:29Error
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException 
June 3rd 2019 13:49:29Error
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,run-command 
June 3rd 2019 13:49:29Error

June 3rd 2019 13:49:31Fatal
The remote script failed with exit code 1 
June 3rd 2019 13:49:31Fatal
The action BizTalk - Deploy Application on DevServer failed 

从数组中,我将像这样创建表:

$title    = [];
$table_rows  = [];

// build table arrays
foreach ($schedule AS $row)
{
    $title[]    = $row->time.' - '.$row->class_name;
    $table_rows[$row->time][$row->class_name][] = ['student_id' => $row->student_id, 'mentor_code' => $row->mentor_code, 'student_name' => $row->student_name];
}

// $title array (using array_unique($title) to removes duplicate values
Array
(
    [0] => 07:30-08:30 - E-1
    [1] => 08:30-09:30 - E-1
    [2] => 10:00-11:00 - E-1
    [3] => 11:00-12:00 - E-1
    [12] => 07:30-08:30 - E-2
    [13] => 08:30-09:30 - E-2
)

// $table_rows array
Array
(
    [07:30-08:30] => Array
        (
            [E-1] => Array
                (
                    [0] => Array
                        (
                            [student_id] => 1012836001
                            [mentor_code] => TPA-1
                            [student_name] => Vanessa
                        )

                    [1] => Array
                        (
                            [student_id] => 1012836002
                            [mentor_code] => TPA-1
                            [student_name] => Kesya
                        )

                    [2] => Array
                        (
                            [student_id] => 3012836003
                            [mentor_code] => TPA-1
                            [student_name] => Charissa
                        )
                )

            [E-2] => Array
                (
                    [0] => Array
                        (
                            [student_id] => 1012836004
                            [mentor_code] => FIS-1
                            [student_name] => Drex
                        )
                    [1] => Array
                        (
                            [student_id] => 3012836005
                            [mentor_code] => FIS-1
                            [student_name] => Vulcano
                        )
                )
        )

    [08:30-09:30] => Array
        (
            [E-1] => Array
                (
                    [0] => Array
                        (
                            [student_id] => 1012836001
                            [mentor_code] => TPA-1
                            [student_name] => Vanessa
                        )
                    [1] => Array
                        (
                            [student_id] => 1012836002
                            [mentor_code] => TPA-1
                            [student_name] => Kesya
                        )
                    [2] => Array
                        (
                            [student_id] => 3012836003
                            [mentor_code] => TPA-1
                            [student_name] => Charissa
                        )
                )

            [E-2] => Array
                (
                    [0] => Array
                        (
                            [student_id] => 1012836004
                            [mentor_code] => FIS-1
                            [student_name] => Drex
                        )
                    [1] => Array
                        (
                            [student_id] => 3012836005
                            [mentor_code] => FIS-1
                            [student_name] => Vulcano
                        )
                )
        )

    [10:00-11:00] => Array
        (
            [E-1] => Array
                (
                    [0] => Array
                        (
                            [student_id] => 1012836001
                            [mentor_code] => FIS-1
                            [student_name] => Vanessa
                        )
                    [1] => Array
                        (
                            [student_id] => 1012836002
                            [mentor_code] => FIS-1
                            [student_name] => Kesya
                        )
                    [2] => Array
                        (
                            [student_id] => 3012836003
                            [mentor_code] => FIS-1
                            [student_name] => Charissa
                        )
                )
        )

    [11:00-12:00] => Array
        (
            [E-1] => Array
                (
                    [0] => Array
                        (
                            [student_id] => 1012836001
                            [mentor_code] => FIS-1
                            [student_name] => Vanessa
                        )
                    [1] => Array
                        (
                            [student_id] => 1012836002
                            [mentor_code] => FIS-1
                            [student_name] => Kesya
                        )
                    [2] => Array
                        (
                            [student_id] => 3012836003
                            [mentor_code] => FIS-1
                            [student_name] => Charissa
                        )
                )
        )
)

我可以根据数组生成结果吗?我真的需要帮助如果有人可以将我指出正确的方向,将不胜感激。谢谢。

1 个答案:

答案 0 :(得分:1)

您可以通过使数组较少多维化来简化此操作。

按完整标题对计划行进行分组:

foreach ($schedule as $row)
{
    $title = "Time : $row->time   $row->mentor_code   Class : $row->class_name";
    $tables[$title][] = $row;
}

然后您将获得一个按标题索引的表数组。从这一点来看,输出每个表要简单得多。

foreach ($tables as $title => $table) {
    echo $title;
    echo '<table>
            <thead>
              <tr>
                <th>Student ID</th>
                <th>Student Name</th>
                <th>Status</th>
              </tr>
            </thead>
            <tbody>';
    foreach ($table as $row) {
        echo "<tr>
                <td>{$row->student_id}</td>
                <td>{$row->student_name}</td>
                <td>Check None</td>
              </tr>"
    }
    echo '</tbody>
          </table>';
}