根据评分在前端显示Star [英] Display Star in Front End based on rating

查看:96
本文介绍了根据评分在前端显示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 < <跨度>&安培;#x2605< /跨度>中;
} 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 <= $ stars; $ 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 backend where using radio button am selecting the rating of product as 1 star, 2 star, 3 star, 4 star and 5 Star

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

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

This is not duplicate I just want users to view star type rating in front end They 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 end Now instead of numeric value as 2 star or 3 star i want stars to be displayed in

Thanks

解决方案

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆