配列があり、複数のテーブルにデータを表示したい。特定の年と学期のすべてのモジュールを単一のテーブルに入れる必要があります。たとえば、すべてのモジュールはsemester_id
と1となります。year 1
単一のテーブル配列データをテーブルに表示
Array
(
[0] => Array
(
[year_id] => 1
[semester_id] => 1
[module_code] => MATH1103C
[module_name] => Decision Mathematics
[module_credit] => 3
)
[1] => Array
(
[year_id] => 1
[semester_id] => 1
[module_code] => ITE1107C
[module_name] => Language and Communication Seminar
[module_credit] => 3
)
[2] => Array
(
[year_id] => 1
[semester_id] => 1
[module_code] => MGMT1101C
[module_name] => Management Seminar
[module_credit] => 3
)
[3] => Array
(
[year_id] => 1
[semester_id] => 1
[module_code] => HCA1105C
[module_name] => Computer Architecture
[module_credit] => 4
)
[4] => Array
(
[year_id] => 1
[semester_id] => 1
[module_code] => PROG1115C
[module_name] => Object Oriented Software Development I
[module_credit] => 4
)
[5] => Array
(
[year_id] => 1
[semester_id] => 2
[module_code] => WAT1116C
[module_name] => Internet Programming I
[module_credit] => 4
)
[6] => Array
(
[year_id] => 1
[semester_id] => 2
[module_code] => MATH1101C
[module_name] => Analytic Methods for Computing
[module_credit] => 4
)
[7] => Array
(
[year_id] => 1
[semester_id] => 2
[module_code] => PROG1116C
[module_name] => Object Oriented Software Development II
[module_credit] => 4
)
[8] => Array
(
[year_id] => 1
[semester_id] => 2
[module_code] => DBT1111C
[module_name] => Database Design
[module_credit] => 4
)
[9] => Array
(
[year_id] => 2
[semester_id] => 1
[module_code] => PROG2117C
[module_name] => Desktop Application Development
[module_credit] => 4
)
[10] => Array
(
[year_id] => 2
[semester_id] => 1
[module_code] => OSS2109C
[module_name] => Operating Systems
[module_credit] => 4
)
[11] => Array
(
[year_id] => 2
[semester_id] => 1
[module_code] => CAN2112C
[module_name] => Network Design & Programming
[module_credit] => 4
)
[12] => Array
(
[year_id] => 2
[semester_id] => 1
[module_code] => WAT2117C
[module_name] => Internet Programming II
[module_credit] => 4
)
[13] => Array
(
[year_id] => 2
[semester_id] => 2
[module_code] => MGMT2104C
[module_name] => Research & Development Seminar
[module_credit] => 3
)
[14] => Array
(
[year_id] => 2
[semester_id] => 2
[module_code] => MCT2104C
[module_name] => Mobile Application Development
[module_credit] => 4
)
[15] => Array
(
[year_id] => 2
[semester_id] => 2
[module_code] => WAT2124C
[module_name] => Web Services
[module_credit] => 4
)
[16] => Array
(
[year_id] => 2
[semester_id] => 2
[module_code] => MATH2323C
[module_name] => Numerical Methods
[module_credit] => 4
)
[17] => Array
(
[year_id] => 2
[semester_id] => 2
[module_code] => SDT2114C
[module_name] => Requirements Engineering
[module_credit] => 4
)
[18] => Array
(
[year_id] => 3
[semester_id] => 1
[module_code] => SEM3112C
[module_name] => Project Management Seminar
[module_credit] => 3
)
[19] => Array
(
[year_id] => 3
[semester_id] => 1
[module_code] => SECU3119C
[module_name] => Secure Software Development
[module_credit] => 4
)
[20] => Array
(
[year_id] => 3
[semester_id] => 1
[module_code] => MULT3114C
[module_name] => Game Development
[module_credit] => 4
)
[21] => Array
(
[year_id] => 3
[semester_id] => 2
[module_code] => PROJ3105C
[module_name] => Systems Development Project
[module_credit] => 9
)
[22] => Array
(
[year_id] => 3
[semester_id] => 2
[module_code] => MGMT3105C
[module_name] => Entrepreneurship Seminar
[module_credit] => 3
)
[23] => Array
(
[year_id] => 3
[semester_id] => 2
[module_code] => SEM3113C
[module_name] => Software Quality Management
[module_credit] => 4
)
[24] => Array
(
[year_id] => 3
[semester_id] => 2
[module_code] => WAT3125C
[module_name] => Emerging Web Technologies
[module_credit] => 4
)
[25] => Array
(
[year_id] => 3
[semester_id] => 2
[module_code] => SDT3104C
[module_name] => Enterprise Software Development
[module_credit] => 4
)
)
にする必要があります。ここに私のコードは、あなたがループの外で静的コード(すなわち、すべて)を配置する必要があり、これまで
if (isset($rows) && is_array($rows)) {
for ($i = 0; $i < count($rows); $i++) {
/*echo 'Year ID: ' . $rows[$i]['year_id'] . '<br>';
echo 'Semester ID : ' . $rows[$i]['semester_id'] . '<br>';
echo 'Module Code' . $rows[$i]['module_code'] . '<br>';*/
echo <<<HTML
<div class="title">
<h1>Year {$rows[$i]['year_id']}</h1>
</div>
<div class="datagrid">
<table>
<thead>
<tr>
<th>Semester {$rows[$i]['semester_id']}</th>
</tr>
</thead>
<thead>
<tr>
<th>Module Code</th>
<th>Module Name</th>
<th>Credits</th>
<th>Grade</th>
</tr>
</thead>
<tbody>
<tr>
<td>{$rows[$i]['module_code']}</td>
<td>{$rows[$i]['module_name']}</td>
<td>{$rows[$i]['module_credit']}</td>
<td>
<select class="combo">
<option value=""> --Grade-- </option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="F">F</option>
</select>
</td>
</tr>
<tr class="al">
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td bgcolor="#b3ffb3"><b>S.P.A</b></td>
<td bgcolor="#4dff4d">data</td>
</tr>
</tbody>
</table>
</div>
HTML;
最初に別の配列を学期と年に従って設計するので、異なる学年と年の別の表を簡単に作成できます。 –
あなたのデータがデータベースから来ているように見えます。単純なアプローチは、フィルタリングされたデータをdbから読み込み、単純なテーブルを出力することです。 –
@Frayne Konokは、この1つから他の配列を作成する方法についての回答を投稿することができます – user2650277