用于剪切重复项的PHP显示逻辑
我有一个MySQL db while结果循环的示例,简单如下:用于剪切重复项的PHP显示逻辑,php,Php,我有一个MySQL db while结果循环的示例,简单如下: echo '<table class="profileTable"> <tr> <td>folder</td> <td>Link</td> <td>actions</td> </tr>
echo '<table class="profileTable">
<tr>
<td>folder</td>
<td>Link</td>
<td>actions</td>
</tr>';
while($row = mysqli_fetch_array($result)) {
echo '<tr><td>'.$row[name].'</td><td><a href="'.$row[url].'">'.$row[title].'</a></td><td>actions here</td></tr>';
}
但我想要的是,第一列仅在与前一列不同时显示,例如:
Coding The Simpsons in CSS actions here
Google SEO starter guide actions here
PHPGang Programming Blog actions here
Shop Amazon actions here
这可能吗?我假定您每次都必须检查第一列的val,但如果该列多次相同,我无法计算出清空该列的逻辑。while($row=mysqli\u fetch\u array($result)){
while($row = mysqli_fetch_array($result)) {
$test = $row[name];
echo '<tr><td>';
if($test != $test2) {
echo $row[name];}else{echo ' ';
}
echo '</td><td><a href="'.$row[url].'">'.$row[title].'</a></td><td>actions here</td></tr>';
$test2 = $test;
}
$test=$row[名称];
回声';
如果($test!=$test2){
echo$row[name];}其他{echo';
}
呼应"这里的行动",;
$test2=$test;
}
是的,差不多就是这样。查看当前值是否与最后一个值匹配,如果不匹配,则将其抑制。我不认为你有任何理由对第一个投票人如此夸耀。这本质上是一个询问代码的问题,而这些代码并不是关于堆栈溢出的主题。非常感谢,在多次使用不同的场景进行循环之后,这让我发疯了!很高兴为您提供帮助!
while($row = mysqli_fetch_array($result)) {
$test = $row[name];
echo '<tr><td>';
if($test != $test2) {
echo $row[name];}else{echo ' ';
}
echo '</td><td><a href="'.$row[url].'">'.$row[title].'</a></td><td>actions here</td></tr>';
$test2 = $test;
}