0

I want to add an image in select option in HTML with PHP.

The image is first fetched from a database.

echo '<option value='.$ifet['productimage'].'><img src='.$ifet['productimage'].'/></option>'; 
dnl-blkv
  • 2,037
  • 1
  • 17
  • 22
user3386779
  • 6,883
  • 20
  • 66
  • 134

3 Answers3

2

images don't work in select infact any type of CSS is not supported in select except line-height and border you can use jquery:

here is a demo: http://designwithpc.com/Plugins/ddSlick#demo

Alex
  • 457
  • 3
  • 16
  • Depends on browser. See [this](http://stackoverflow.com/a/2966006/4405465) solution for adding SVG-images in FireFox – Hasse Björk Nov 21 '15 at 23:23
2

To add images in a select list you'll have to add them as a background-image.

<select>
    <option value='displayvalue' style='background-image:url(".print $ifet['productimage'].");'></option>
</select>

or use it as CSS

select option[value='displayvalue']
{background-image:url(".print $ifet['productimage'].");}
0

Try this

<option value="<?=$ifet['productimage']?>"><img src="<?=$ifet['productimage']?>" /></option>

OR

<option value="<?php echo $ifet['productimage']; ?>"><img src="<?php echo $ifet['productimage']; ?>" /></option>