我有一個數組,我想要在多個表中顯示數據。特定年份和學期的所有模塊應該在一個表中。例如,在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;
首先根據學期和年份設計另一個陣列,以便您可以輕鬆訪問爲不同的學期和年份繪製不同的表格。 –
它看起來像你的數據來自數據庫。一個簡單的方法是從數據庫讀取過濾的數據並輸出簡單的表格。 –
@Frayne Konok你可以發表一個關於如何從這個人創建另一個數組的答案 – user2650277