-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 –