php - 使用php中动态创建的单选按钮的onclick标签更改图像

标签 php html mysql

<?php 
$query = "SELECT img_path FROM oc_product_color Order by color_id" ; 
$result = mysql_query($query) ;
$counter = 0 ;
$z=0;
while($row = mysql_fetch_assoc($result))
   {
        $color[$counter] = $row['img_path'];
       $counter = $counter + 1;
   }
?>
<div>
    <font size="4">Choose Your Product Color:</font>
</div>
<style>
    label > input{ /* HIDE RADIO */
    visibility: hidden;
    position: absolute;
    }
    label > input + img{ /* IMAGE STYLES */
    cursor:pointer;
    border:2px solid transparent;
    }
    label > input:checked + img{ /* (RADIO CHECKED) IMAGE STYLES */
    border:2px solid #A8813E;
    }
</style>
<style>
    .grow img {
    height: 24px;
    width: 24px;
    -webkit-transition: all 1s ease;
    -moz-transition: all 1s ease;
    -o-transition: all 1s ease;
    -ms-transition: all 1s ease;
    transition: all 1s ease;
    }
    .grow img:hover {
    width: 50px;
      height: 50px;
    }
</style>

<div>
            <?
            if($counter>0)
                {
                        for($z=0;$z<$counter;$z++)
                            {
                            ?> 
            <tr >
                <?
                    if($z<$counter)
            {
                ?>
                <label class="grow pic">
                    <input type="radio" name="color" checked="checked" value="small" onclick =  />
                    <img src=<?php echo $color[$z];?> width="16px" height="16px" />
                </label>
                <?
            }   
            ?>   

            </tr>

     <? }
     }  ?>
        </a></div>
</div>
<label for="color"><img src = "<?php echo $color[$z] ?>"></label>
</div>
<br>
</div>

亲爱的 Stackoverflow

我尝试获取与其关联的图像路径并显示它,但徒劳无功:

<label for="color"><img src = "<?php echo $color[$z] ?>"></label>

我是 php 新手,并且已经成功完成了这段代码

任何帮助将不胜感激

抱歉我的英语不好

感谢和问候
Akki2401

最佳答案

我不确定你在问什么,但我觉得这就是你正在寻找的!试试这个!

<div class="radio-buttons">
    <input type="radio" name="rGroup" value="1" id="r1" checked="checked" />
    <label class="radio-label" for="r1"></label>
    <input type="radio" name="rGroup" value="2" id="r2" />
    <label class="radio-label" for="r2"></label>
    <input type="radio" name="rGroup" value="3" id="r3" />
    <label class="radio-label" for="r3"></label>
</div>

和CSS

.radio-buttons .radio-label{
    background-color:#E8C504;
    display:inline-block;
    width:40px;
    height:40px;
    border-radius:40px;
}

.radio-buttons input[type=radio]{
    display:none
}

.radio-buttons input[type=radio]:checked + .radio-label{
    background-color:#241009
}

尝试在这里拨弄http://jsfiddle.net/raghuchandrasorab/qzjddx6v/

关于php - 使用php中动态创建的单选按钮的onclick标签更改图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26668587/

相关文章:

php - 拉拉维尔 8 : Undefined variable when loading a Blade into another Blade

php - 如何转换字符串日期以与数据库中的日期进行比较,PHP

mysql - Laravel 5.7 - when() 函数内的高级 where() 查询

php - array_merge 与 union 在 PHP 中的性能

php + jquery ajax 请求使用过多CPU

html - 在 amp-img 中设计响应式布局

javascript - 我如何将rails form_helper标签附加到html

css - 背景视频覆盖了 Chrome 中页面的其余部分

mysql - SQL 查询总和乘以 2 倍应该是多少

mysql - 多个查询中的第一个现有行