【发布时间】:2019-05-06 13:26:06
【问题描述】:
每个人。我是新来的,也是 PHP 的新程序员。我正在建立一个排名,并希望你们帮助我解决排名关系,因为在我试图找到完美的排名解决方案时,我一直坚持给出正确的排名。代码将解释我想要更好地实现的目标:
<?php
if ($dados == "") {
$totalWebservice1 = 0;
$position = 1;
$mat = '';
$id = '';
foreach ($resultAll as $dado) {
$group = $insert->selectGrupo($dado['codClient']);
if ($dado['codClient'] == $group['id_sponte'] && $group['group'] == 'yellow' && $topOne['codClient'] != $dado['codClient']) {
$totalWebservice1 = $totalWebservice1 + $dado['registration'];
?>
<tr>
<td><?php echo $position?>º</td>
<td><?php echo $dado['name'] ?></td>
<td><?php echo $dado['registration'] ?></td>
<?php
if ($dado['registration'] != $mat || $dado['name'] != $id) { // if not the same id.
$position++;
}
?>
</tr>
<?php
$mat = $dado['registration'];
$id = $dado['name'];
}
}
} else {
$totalMatriculas1 = 0;
?>
输出:
Position Name Registration
1° teste 4
2° teste 2
3° teste 2
3° teste 2
3° teste 2
3° teste 1
预期输出:
Position Name Registration
1° teste 4
2° teste 2
2° teste 2
2° teste 2
2° teste 2
3° teste 1
问题在于它将排名打印为1,2,3,3,3,3,而根据我的假设它应该打印1,2,2,2,2,3。那么它如何打印1,2,2,3?哪里可能出问题?
【问题讨论】:
-
请发布所有相关代码(包括循环)。那里有变量,我们不知道它们是如何或在哪里填充的。
-
对不起,我再次添加了整个代码。
标签: php