【发布时间】:2015-09-15 01:44:36
【问题描述】:
我的数据库中有 3 条评论,但不知何故,它只显示 3 条星级中的 1 条已选中,而其他 2 条评论的星级为空
@foreach($recensies as $recensie)
<fieldset class="rating">
<input type="radio" disabled @if($recensie->rating == 5) checked="checked" @endif name="rating" value="5" /><label class = "full" for="star5" title="Awesome - 5 stars"></label>
<input type="radio" disabled @if($recensie->rating == '4 and a half') checked="checked" @endif name="rating" value="4 and a half" /><label class="half" for="star4half" title="Pretty good - 4.5 stars"></label>
<input type="radio" disabled @if($recensie->rating == 4) checked="checked" @endif name="rating" value="4" /><label class = "full" for="star4" title="Pretty good - 4 stars"></label>
<input type="radio" disabled @if($recensie->rating == '3 and a half') checked="checked" @endif name="rating" value="3 and a half" /><label class="half" for="star3half" title="Meh - 3.5 stars"></label>
<input type="radio" disabled @if($recensie->rating == 3) checked="checked" @endif name="rating" value="3" /><label class = "full" for="star3" title="Meh - 3 stars"></label>
<input type="radio" disabled @if($recensie->rating == '2 and a half') checked="checked" @endif name="rating" value="2 and a half" /><label class="half" for="star2half" title="Kinda bad - 2.5 stars"></label>
<input type="radio" disabled @if($recensie->rating == 2) checked="checked" @endif name="rating" value="2" /><label class = "full" for="star2" title="Kinda bad - 2 stars"></label>
<input type="radio" disabled @if($recensie->rating == '1 and a half') checked="checked" @endif name="rating" value="1 and a half" /><label class="half" for="star1half" title="Meh - 1.5 stars"></label>
<input type="radio" disabled @if($recensie->rating == 1) checked="checked" @endif name="rating" value="1" /><label class = "full" for="star1" title="Sucks big time - 1 star"></label>
<input type="radio" disabled @if($recensie->rating == 'half') checked="checked" @endif name="rating" value="half" /><label class="half" for="starhalf" title="Sucks big time - 0.5 stars"></label>
</fieldset>
@endforeach
这是一张图片来告诉你我的意思。
【问题讨论】:
-
这 3 个新近度的评分值是多少?也许你可以用
$recensie->rating输出它们?无论如何2 and a half作为评级值对我来说看起来有点麻烦。为什么你不使用2.5来代替?所以值类型是double或float但不是string。
标签: laravel if-statement foreach blade