首页 > 解决方案 > 如果结果 = 0,我如何禁用表格行

问题描述

你好,我的桌子在这里

截图在这里

汇总表 表现在我想在汇总表中如果“Menge” = 0,则表格行不会显示在汇总中,这意味着在实际图片中只有“10.95:7”必须蜜蜂显示我当前的 zhhe 汇总表的表格代​​码

    <div class="box">
      <div class="box-header">
      <h3 class="box-title">Zusammenfassung</h3>
      </div>
      <div class="box-body">
        <table class="table table-bordered table-striped">
          <tr>
            <th>Ware</th>
            <th>Menge</th>
          </tr>
          <tbody>
            <tr>
              <td>4.95</td>
              <td><?php echo $count->countRow($lid, 4.95); ?></td>
            </tr>
            <tr>
              <td>5.95</td>
              <td><?php echo $count->countRow($lid, 5.95); ?></td>
            </tr>
            <tr>
              <td>7.95</td>
              <td><?php echo $count->countRow($lid, 7.95); ?></td>
            </tr>
            <tr>
              <td>9.95</td>
              <td><?php echo $count->countRow($lid, 9.95); ?></td>
            </tr>
            <tr>
              <td>10.95</td>
              <td><?php echo $count->countRow($lid, 10.95); ?></td>
            </tr>
            <tr>
              <td>11.95</td>
              <td><?php echo $count->countRow($lid, 11.95); ?></td>
            </tr>
            <tr>
              <td>12.95</td>
              <td><?php echo $count->countRow($lid, 12.95); ?></td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>

和类函数

public function countRow($lid, $price){
    $result = $this->sql->query("SELECT count(*) FROM lieferschein2_ware where ean = '$price' and l_id = $lid");
    $res = mysqli_fetch_array($result);

    if($result->num_rows === 0){
        return 0;
    }else{
        return $res["count(*)"];
    }
}

表函数显示主表和用户信息

<div class="box-body">
    <table id="example1" class="table table-bordered table-striped">
    <thead>
    <tr>
        <th>ID</th>
        <th>Preis</th>
        <th>status</th>
        <th>Aktion</th>                  
    </tr>
    </thead>
    <tbody>
<?php while($waren = mysqli_fetch_array($ware)) {   

        echo "<tr>";
        echo "<td>" . $waren["id"] . "</td>";
        echo "<td>" . $waren['ean'] . "</td>";
        echo "<td>" . $waren['status'] . "</td>";
        echo '<td><form method="post"><button type="submit" name="del" value='. $waren["id"] .' class="btn btn-danger btn-xs">Löschen</button></a></form></td>';
        echo "</tr>";

} 
?>
    </tbody>
    <tfoot>
        <tr>
            <th>ID</th>
            <th>Preis</th>
            <th>status</th>
            <th>Aktion</th>                
        </tr>
    </tfoot>
    </table>
    </div>
</div>

标签: phpsql

解决方案


menge您需要在要检查的每一行大于 0之前应用 if 条件,如下所示:

<div class="box">
      <div class="box-header">
      <h3 class="box-title">Zusammenfassung</h3>
      </div>
      <div class="box-body">
        <table class="table table-bordered table-striped">
          <tr>
            <th>Ware</th>
            <th>Menge</th>
          </tr>
          <tbody>
            <?php if ($count->countRow($lid, 4.95) > 0) { ?>
            <tr>
              <td>4.95</td>
              <td><?php echo $count->countRow($lid, 4.95); ?></td>
            </tr>
            <?php } ?>           
          </tbody>
        </table>
      </div>
    </div>

你需要if对每一行应用这个条件。


推荐阅读