0

I am trying to display images from my database using the select and option tags but images dont display.

<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>

loop is correct and image path function is also correct as i have used in other options. All i need is for the images to display so i can select for another usage.

sanmexma
  • 75
  • 7
  • Note that the permitted content for ` – showdev Jun 29 '19 at 10:17
  • 1
    Possible duplicate of [Putting images with options in a dropdown list](https://stackoverflow.com/questions/4941004/putting-images-with-options-in-a-dropdown-list) – showdev Jun 29 '19 at 10:18

1 Answers1

1

First create dynamic class and set background-image in class then apply class in option tag

<div class="form-group col-md-6">
      <label for="inputtype">Game Type</label>
      <select class="custom-select mr-md-2" name="image_file">
       <option selected></option>
       <?php foreach($games as $image): ?>
         <script>
           .image-option<?php echo $image->image_path(); ?>{
              background-image: '<?php echo $image->image_path(); ?>';
              width:"40";
              height="40";
           }
         </script>
        <option class='image-option<?php echo $image->image_path(); ?>' value="<?php echo $image->region ?>"></option>
        <?php endforeach; ?>
      </select>
</div>
Nirav Sutariya
  • 317
  • 4
  • 14