【问题标题】:How do I hide entire row if a certain cell in that row is empty?如果该行中的某个单元格为空,如何隐藏整行?
【发布时间】:2016-03-31 08:05:04
【问题描述】:

我已经被这个问题困扰了一段时间了。如果未填写 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();

【问题讨论】:

  • 你为什么要做不必要的 parent().children() ???只需这样做:$('table').find("td:nth-child(2):empty").parent().hide();
  • 是的 svar=answer,抱歉我之前没有澄清
  • 那么只更新查询以不选择不需要的记录呢?

标签: php jquery mysql html-table


【解决方案1】:

你可以试试这个:

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

这里是FIDDLE

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

    • 同意这一点,因为您不需要客户端代码。
    猜你喜欢
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    • 2015-10-27
    • 2023-03-27
    • 2014-09-06
    • 1970-01-01
    • 2015-12-08
    相关资源
    最近更新 更多