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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,