如果標題寫得不好,我很抱歉,因爲我不確定究竟是什麼稱呼它!循環不重複在表列中的值
我有一個非常基本的表設置:employees和employees_deductions。我想加入這兩個並使用php在表格中顯示內容。
我得到的員工:
$employees = $wpdb->get_results("SELECT * from employees");
我然後遍歷$employees
,並在每一個,我得到的扣除額,則在表中顯示它們:(代碼下面簡化的)
foreach($employees as $emp) {
$deductions = $wpdb->get_results("SELECT * FROM employee_deductions WHERE employee_id = $this_employee_id");
foreach($deductions as $ded) {
<tr>
<td>name</td>
<td>deduction</td>
</tr>
}
}
我的問題是如何獲得第一個包含「BLANK」上面的「名稱」的單元格,如果它正上方的行中的單元格包含相同的確切「名稱」?
什麼我越來越:
+------+-----------+
| name | deduction |
+------+-----------+
| John | 100 |
| John | 142 |
| John | 204 |
| Mary | 200 |
| Mary | 340 |
+------+-----------+
期望的結果:
+------+-----------+
| name | deduction |
+------+-----------+
| John | 100 |
| | 142 |
| | 204 |
| Mary | 200 |
| | 340 |
+------+-----------+
你在寫PHP和HTML中的一個序列沒有開始或結束PHP?併爲答案請嘗試由mysql的組 –