Php 如果行中的某个单元格为空,如何隐藏整行?
我已经被这件事困扰了一段时间了。如果第二列(svar)单元格在所有未填充svar下单元格的行上为空,如何隐藏行 以下是我目前的代码: PHPPhp 如果行中的某个单元格为空,如何隐藏整行?,php,jquery,mysql,html-table,Php,Jquery,Mysql,Html Table,我已经被这件事困扰了一段时间了。如果第二列(svar)单元格在所有未填充svar下单元格的行上为空,如何隐藏行 以下是我目前的代码: PHP $localhost = "localhost"; $username = "root"; $password = ""; $connect = mysqli_connect($localhost, $username, $password)or die("Kunde inte koppla"); mysqli_select_db($connect,
$localhost = "localhost";
$username = "root";
$password = "";
$connect = mysqli_connect($localhost, $username, $password)or
die("Kunde inte koppla");
mysqli_select_db($connect, 'wildfire');
$result = mysqli_query($connect,"SELECT * FROM question");
echo "<table border='1'>
<tr>
<th>Fråga</th>
<th>Svar</th>
<th>Poäng</th>
<th>Redigera</th>
<th>Radera</th>
<th>AID</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['qid'] . "</td>";
echo "<td>" . $row['answer'] . "</td>";
echo "<td>" . $row['Point'] . "</td>";
echo "<td><a href=\"editdilemman.php?aid=".$row['aid']."\">Redigera</a></td>";
echo "<td><a href=\"radera.php?id=".$row['aid']."\">Ta bort</a></td>";
echo "<td>" . $row['aid'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($connect);
您可以尝试以下方法:
$('td:nth-child(2):empty').closest('tr').hide();
这是一个问题。我将更新查询,以便您只返回希望显示的记录。因此,改变:
$result = mysqli_query($connect,"SELECT * FROM question");
到
$result=mysqli_query($connect,“从答案为“”的问题中选择*&&answer不为空”);
为什么要做不必要的父项().子项()???只需执行以下操作:$('table').find(“td:nth child(2):empty”).parent().hide()
Yes svar=answer,很抱歉,我之前没有澄清过,那么只更新查询以不选择不需要的记录怎么样?同意这一点,因为您不需要客户端代码。
$result = mysqli_query($connect,"SELECT * FROM question");
$result = mysqli_query($connect,"SELECT * FROM question where answer <> '' && answer IS NOT NULL");