【发布时间】:2015-09-13 04:36:54
【问题描述】:
我有一个在 mysql 中进行查询的 PHP 页面,但我有可重复的结果,我想加入它们。我希望这是结果:
Client Type Analysis
1 1 0001
0002
2 0010
2 1 1110
但我的实际结果是这样的:
Client Type Analysis
1 1 0001
1 0002
2 0010
2 1 1110
这是我正在使用的代码:
$query = mysqli_query( $db, 'SELECT * FROM laudos ORDER BY cliente, tipo');
$cli = array();
while($row = $query->fetch_assoc()) {
$cli[$row['cliente']][] = $row;
}
?>
<table border="1" cellpadding="10">
<tr>
<td>Cliente</td>
<td>Tipo</td>
<td>Análises</td>
</tr>
<?php
foreach($cli as $cliente => $values){
?>
<tr>
<td><?php echo $cliente; ?></td>
<?php foreach($values as $resul) { ?>
<tr>
<td></td>
<td>
<?php echo $resul['tipo'];?>
</td>
<td>
<select>
<option SELECTED>Escolha um laudo</option>
<option><?php echo $resul['legisla'].'-'.$resul['numero'];}?></option>
</select>
</td>
</tr>
</tr>
<?php } ?>
编辑:我想按列分组Type
【问题讨论】:
-
I want to join it,你必须解释你想做什么。现在我们帮不了你了。 -
那么,您想加入还是删除重复项?请更具体。
-
是否要将表连接到自身?
-
通常您使用连接从两个或多个表中选择一些数据。在你的情况下,我只看到一个。