dongyao8698 2017-02-10 12:15
浏览 56
已采纳

当值为0时,不要在表中显示列

I have a table with three ligne and three column in a php page, I want to know how to not show a ligne when the value of data sent from the database is 0?

here is the table

I have always data sent from the database to the 2 lignes in blue but for the red one there is not always data sent to this ligne, so I want to know how to hide this ligne when there is not a data sent from the database. The code that I have actually:

<table class="table-striped" id="">
  <tr>
    <th>Title 1</th>
    <th>Title 2</th>
    <th>Title 3</th>
    <th>Title 4</th>
  </tr>
  <tbody>
    <tr>
      <td>
        <?php echo $td1; ?>
      </td>
      <td>
        <?php echo $td2; ?>
      </td>
      <td>
        <ul>
          <?php echo $td3; ?>
        </ul>
      </td>
      <td>
        <ul>
          <?php echo $td4; ?>
        </ul>
      </td>
    </tr>
    <tr>
      <td>
        <?php echo $td5; ?>
      </td>
      <td>
        <?php echo $td6; ?>
      </td>
      <td>
        <ul>
          <?php echo $td7; ?>
        </ul>
      </td>
      <td>
        <ul>
          <?php echo $td8; ?>
        </ul>
      </td>
    </tr>
    <!-- the ligne bellow that i want to no show if the data sent is 0   -->
    <tr>
      <td>
        <?php echo $td9; ?>
      </td>
      <td>
        <?php echo $td10; ?>
      </td>
      <td>
        <ul>
          <?php echo $td11; ?>
        </ul>
      </td>
      <td>
        <ul>
          <?php echo $td12; ?>
        </ul>
      </td>
    </tr>
  </tbody>
</table>
  • 写回答

1条回答 默认 最新

  • duanfei9278 2017-02-10 13:08
    关注

    If you have nothing in $td9 or $td10 or ... it means there is no 3rd row in database result, so put the if before 3rd data row!

      <table class="table-striped" id="">
         <tr>
         <th>Title 1</th>
         <th>Title 2</th>
         <th>Title 3</th>
         <th>Title 4</th>
         </tr> 
         <tbody>
         <tr>
         <td><?php echo $td1; ?></td>
         <td> <?php echo $td2; ?></td>
         <td>
         <ul>
          <?php echo $td3; ?>
         </ul>
         </td>
         <td>
         <ul>
          <?php echo $td4; ?> 
         </ul>
         </td>
         </tr>
         <tr>
         <td><?php echo $td5; ?></td>
         <td><?php echo $td6; ?></td>
         <td>
         <ul><?php echo $td7; ?> </ul>
         </td>
         <td>
         <ul><?php echo $td8; ?></ul>
         </td>
         </tr>
         <!-- the ligne bellow that i want to no show if the data sent is 0   --> 
      <?php if($td9){ ?>
         <tr>
         <td><?php echo $td9; ?></td>
         <td><?php echo $td10; ?></td>
         <td>
         <ul><?php echo $td11; ?></ul>
         </td>
         <td>
         <ul><?php echo $td12; ?></ul>
         </td>
         </tr>
      <?php } ?>
         </tbody>
     </table>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了