Display Star in Front End based on rating

前端 未结 5 1617
名媛妹妹
名媛妹妹 2021-01-29 09:49

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 s

5条回答
  •  太阳男子
    2021-01-29 10:31

    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:

    prodDet->v_child_safety;
    $count = 1;
    $result = "";
    
    for($i = 1; $i <= 5; $i++){
        if($stars >= $count){
            $result .= "";
        } else {
            $result .= "";
        }
        $count++;
    }
    ?>
    

    Expert Rating -

    If you want to use images of a star instead, use this code:

    prodDet->v_child_safety;
    $result = "";
    
    for($i = 1; $i <= $stars; $i++){
        $result .= "";
    }
    ?>
    

    Expert Rating -

提交回复
热议问题