本文介绍了根据评分在前端显示Star的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在后台中创建了一个字段,其中使用单选按钮选择产品的评分为1星,2星,3星,4星和5星 在显示相同的前端时 < p class =tool-tip>< a href =#onMouseover =ddrivetip('Expert Rating'); onMouseout =hideddrivetip()>专家评分< / a> - <?php echo $ this-> prodDet-> v_child_safety?>< / p> 它以数字形式显示评分 - 1星,2星,3星,4星和5星 任何一个指南都可以让前端显示星级,而不会使页面加载变慢 $ b 这不是重复的我只希望用户查看前端的星型评分他们无法修改评分或添加评分,它只是管理员分配评级为1星到5星,并在前端可见现在,而不是数值作为2星或3星我希望明星显示在 谢谢 首先,确保 $ this-> prodDet - > v_child_safety 只会返回一个数字。因此,而不是1星级,2星级,它应该只是返回1,2,3等,然后用这个替换你的代码: <?php $ stars =(int)$ this-> prodDet-> v_child_safety; $ count = 1; $ result =; ($ $> = $ count){ $ result。= $($ i = 1; $ i } else { $ result。=< span>&#x2606< / span>; } $ count ++; } ?> < p class =tool-tip>< a href =#onMouseover =ddrivetip('Expert Rating'); onMouseout =hideddrivetip()>专家评分< / a> - <?php echo $ result?>< / p> 如果您想使用星形图像,请使用以下代码: <?php $ stars =(int)$ this-> prodDet-> v_child_safety; $ result =; $ b $ for($ i = 1; $ i $ result。=< img src ='link_to_image_here.png'/> ; } ?> < p class =tool-tip>< a href =#onMouseover =ddrivetip('Expert Rating'); onMouseout =hideddrivetip()>专家评分< / a> - <?php echo $ result?>< / p> I have created a field in backendwhere using radio button am selecting the rating of product as 1 star, 2 star, 3 star, 4 star and 5 StarIn front end when displaying same<p class="tool-tip"><a href="#" onMouseover="ddrivetip('Expert Rating')"; onMouseout="hideddrivetip()">Expert Rating</a> - <?php echo $this->prodDet->v_child_safety?></p>It displays the rating in numeric form as - 1 star, 2 star, 3 star, 4 star and 5 StarCan any one guide on the best way to have front end display a Star like rating instead of numeric value without making the page load slowThis is not duplicateI just want users to view star type rating in front endThey can not modify rating or add a rating, its just that the administrator assigns a rating as 1 star to 5 star and its viewable in the front endNow instead of numeric value as 2 star or 3 star i want stars to be displayed inThanks 解决方案 First, make sure $this->prodDet->v_child_safety only returns a number. So instead of 1 star, 2 star, it should just return 1, 2, 3 etc. Then replace your code with this:<?php$stars = (int)$this->prodDet->v_child_safety;$count = 1;$result = "";for($i = 1; $i <= 5; $i++){ if($stars >= $count){ $result .= "<span>&#x2605</span>"; } else { $result .= "<span>&#x2606</span>"; } $count++;}?><p class="tool-tip"><a href="#" onMouseover="ddrivetip('Expert Rating')"; onMouseout="hideddrivetip()">Expert Rating</a> - <?php echo $result?></p>If you want to use images of a star instead, use this code:<?php$stars = (int)$this->prodDet->v_child_safety;$result = "";for($i = 1; $i <= $stars; $i++){ $result .= "<img src='link_to_image_here.png'/>";}?><p class="tool-tip"><a href="#" onMouseover="ddrivetip('Expert Rating')"; onMouseout="hideddrivetip()">Expert Rating</a> - <?php echo $result?></p> 这篇关于根据评分在前端显示Star的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-11 04:10