-1
我有一個數據庫(MySQL的)表像PHP輸出重複值的foreach
id | assign_id | rights | party
---+-------------+------------+---------
1 |5 | 12 | xyz
2 |5 | 3 | xyz
3 |6 | 14 | abc
4 |6 | 5 | abc
現在,我想讓我的表格格式輸出以這種方式使用PHP的foreach
| assign_id | rights | party
---+-------------+------------+---------
|5 | 12,3 | xyz
|6 | 5,14 | abc
的表結構是
<th> Assign ID. </th>
<th> Party Name </th>
<th> rights</th>
</tr>
</thead>
<tbody>
<?php if(is_array($aryAssign)) {
$cntuser=1;
foreach($aryAssign as $aryAssign){ ?>
<tr>
<td> <?php echo $aryAssign['assign_id']; ?> </td>
<td> <?php echo $aryAssign['party']; ?> </td>
<td> <?php echo $aryAssign['rights']; ?> </td>
</tr>
<?php } } ?>
</tbody>
</table>
查詢重複值,然後打印在表中。 –
你現在的過程是什麼? –
你應該在你的sql查詢中使用GROUP_CONCAT和GROUP BY –