我有以下脚本来检索sql数据:
// Present data if avail
if ($result->num_rows > 0) {
// Query output in tabels
while($row = $result->fetch_assoc()) {
echo '<tr> <td class="tg">' .$row["id"]. '</td>' . "\n";
echo '<td class="tg">' .$row["fname"]. '</td>' . "\n";
echo '<td class="tg">' .$row["lname"]. '</td>' . "\n";
echo '<td class="tg">' .$row["make"]. '</td></tr>' . "\n";
}
// if no records
} else {
echo "0 results";
}
如何替换空字符串'fname'行中的重复项? (记录按fname排序)
答案 0 :(得分:0)
您向我们展示的脚本不会检索SQL数据 - 它只是显示它。如果您设法编写上面的代码,那么这应该是显而易见的:
$prevname='';
while($row = $result->fetch_assoc()) {
echo '<tr> <td class="tg">' .$row["id"]. '</td>' . "\n";
echo '<td class="tg">'
. ( $row["fname"] == $prevname ? '' : $row["fname"])
. '</td>' . "\n";
echo '<td class="tg">' .$row["lname"]. '</td>' . "\n";
echo '<td class="tg">' .$row["make"]. '</td></tr>' . "\n";
$prevname=$r["fname"];
}