如何使用选项在php中显示数据库中的图像并选择

我正在尝试使用 select 和 option 标签显示我的数据库中的图像,但图像不显示。


<div class="form-group col-md-6">

      <label for="inputtype">Game Type</label>

      <select class="custom-select mr-md-2" name="image_file">

       <?php foreach($games as $image): ?>

        <option selected></option>

        <option value="<?php echo $image->region ?>"><img src="<?php echo $image->image_path(); ?>" width="40" height="40" style="border-radius: 100%; "/></option>

        <?php endforeach; ?>

      </select>

          </div>

循环正确,图像路径功能也正确,因为我在其他选项中使用过。我只需要显示图像,以便我可以选择其他用途。


料青山看我应如是
浏览 162回答 1
1回答

幕布斯6054654

首先创建动态类并在类中设置背景图像,然后在选项标签中应用类<div class="form-group col-md-6">&nbsp; &nbsp; &nbsp; <label for="inputtype">Game Type</label>&nbsp; &nbsp; &nbsp; <select class="custom-select mr-md-2" name="image_file">&nbsp; &nbsp; &nbsp; &nbsp;<option selected></option>&nbsp; &nbsp; &nbsp; &nbsp;<?php foreach($games as $image): ?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<script>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.image-option<?php echo $image->image_path(); ?>{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-image: '<?php echo $image->image_path(); ?>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:"40";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height="40";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</script>&nbsp; &nbsp; &nbsp; &nbsp; <option class='image-option<?php echo $image->image_path(); ?>' value="<?php echo $image->region ?>"></option>&nbsp; &nbsp; &nbsp; &nbsp; <?php endforeach; ?>&nbsp; &nbsp; &nbsp; </select></div>
打开App,查看更多内容
随时随地看视频慕课网APP