dongruyan4948 2019-05-20 08:07
浏览 345

如何在没有数据时隐藏选择选项

I'm building a drop-down list with options containing data from a database and want to hide options which have zero data.

I have tried an if statement using continue but failing to catch the live data values from the database.

      <select name='Database' title="Choose from database">
        <option value="">All</option>
        <?php foreach($database as $row):
          if ($row['topic'] == 0) {
            continue;
          }
          else {
          ?>
            <option value="<?= $row['topic']; ?>"
            <?php if ($row['topic'] == $_SESSION['prosess']){echo " 
            selected";}?>>
            <?= $row['topic']; ?>
          <?php }?>
          </option>
        <?php endforeach; ?>
      </select>

Is there any clever javascript-, php-, etc. code that can deactivate/hide options from a database which are empty.

  • 写回答

2条回答 默认 最新

  • donglue8180 2019-05-20 08:14
    关注

    Add this in your css:

    select option:empty { display:none }

    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本