我有一个MySQL db while循环结果的例子,只是这个:
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
Coding Google SEO starter guide actions here
Coding PHPGang Programming Blog actions here
Shop Amazon actions here
但我想要的是第一个col只显示它与前一个colval不同的例如:
Coding The Simpsons in CSS actions here
Google SEO starter guide actions here
PHPGang Programming Blog actions here
Shop Amazon actions here
这可能吗?我认为你必须每次检查第一个col的val,但是如果它的次数相同,我就无法计算出空白列的逻辑。
答案 0 :(得分:2)
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;
}