如果该行中的某个单元格为空,如何隐藏整行?

时间:2015-12-25 05:20:11

标签: 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, '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);

JQuery的

 var t = $('table').parent().children().find("td:nth-child(2):empty").parent().hide();

2 个答案:

答案 0 :(得分:2)

我会更新查询,因此您只返回要显示的记录。所以改变:

$result = mysqli_query($connect,"SELECT * FROM question");

$result = mysqli_query($connect,"SELECT * FROM question where answer <> '' && answer IS NOT NULL");

答案 1 :(得分:1)

你可以试试这个:

$('td:nth-child(2):empty').closest('tr').hide();

这是FIDDLE