我怎样才能直接在 mysql 问题中或在 php 中使输出看起来像这样?标记 Angelas tips_number 3 在表中丢失,我想在输出中将其重新编号为 1-3。此外,只有具有多个 tips_number 的 ID 才应在其名称后加上数字。
George Danton
Herbert G Wells (1)
Herbert G Wells (2)
Angela (1)
Angela (2)
Angela (3)
+--------+------------------+--------------+
| id | name | tips_number |
+--------+------------------+--------------+
| 1 | Georges Danton | 1 |
| 2 | Herbert G Wells | 1 |
| 2 | Herbert G Wells | 2 |
| 3 | Angela | 1 |
| 3 | Angela | 2 |
| 3 | Angela | 4 |
+--------+------------------+--------------+
我得到的最接近的是这个
foreach($id as $row)
{
if($row['tips_number'] > 1){
$tip_number = $row['tips_number'];
$name = $row['name'];
$result = "{$name} ($tip_number)";
}
else $result = $row["name"];
echo "$result <br>";
}
哪个得到输出
George Danton
Herbert G Wells
Herbert G Wells (2)
Angela
Angela (2)
Angela (4)
MM们