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>';
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>';
Share
Improve this question
edited Mar 12, 2014 at 7:56
dnl-blkv
2,1281 gold badge17 silver badges23 bronze badges
asked Mar 12, 2014 at 7:49
user3386779user3386779
7,21521 gold badges73 silver badges141 bronze badges
3
- I get blank option in select box using <img src=> – user3386779 Commented Mar 12, 2014 at 7:51
- see stackoverflow./a/2966006/1501051 – عثمان غني Commented Mar 12, 2014 at 7:53
- Possible duplicate of How to add a images in select list – Kevin Brown-Silva Commented Jan 1, 2017 at 17:23
3 Answers
Reset to default 2images 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./Plugins/ddSlick#demo
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'].");}
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>