检索数字并转为星号 [英] Retrieve numbers and turn as star

查看:88
本文介绍了检索数字并转为星号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以显示我的数据库号吗? 3是使用PHP的超棒数字吗?

Is that possible to I show my database number eg. 3 as font-awesome numbers using PHP?

我有一个推荐表,人们可以在其中写下他们的反馈并给星星(这些星星保存为1到5),现在我可以在模板中以数字的形式显示出来,但是我想知道仍然可以显示它们作为字体图标?

I have Testimonials table where people write their feedback and give stars (these stars save as number 1 to 5), now i can show then in my template as number it is, but i want to know is there anyway to show them as font-icon?

使用:Laravel PHP框架.

Using: Laravel PHP framework.

我将其添加到了我的testimonial模型中,现在我返回了星星,但问题是它们都是空星星,没有为选定的数字着色.

I added this to my testimonial model and now i return stars but issue is all of them are empty stars and not get color to selected numbers.

public function tesstars()
  {
    $rates = '';
    $stars = floor($rates);

    $rates = '';
    $j = 0;
    for ($i = 0; $i < 5; $i++) {
      for ($j; $j < $stars; $j++) {
        $rates .= '<span class="fa fa-star"></span>';
        $i++;
      }
      if ($i < 5) {
        $rates .= '<span class="fa fa-star-o"></span>';
      }
    }
    return $rates;
  }

推荐答案

已解决

好吧,因为我无法从模型中实现这一点,所以我决定将其替换为其他东西,否则将其插入刀片中并手动在其中加载星星.

SOLVED

Well as I couldn't make it happen from model I decided to make else,elseif in my blade and load stars manually in there.

感谢所有帮助.

@if($testimonial->star == 1)
<span class="fa fa-star"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
@elseif($testimonial->star == 2)
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
@elseif($testimonial->star == 3)
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
@elseif($testimonial->star == 4)
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star-o"></span>
@else($testimonial->star == 5)
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
@endif

这篇关于检索数字并转为星号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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