Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7793689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:34:03+00:00 2026-06-01T22:34:03+00:00

So, my question is very strait forward, I have a single variable, per say

  • 0

So, my question is very strait forward, I have a single variable, per say 4, and I need to translate it to some kind of rating, very simple ( it goes from 1 to 5 ) without half stars or anything.

I need to display a rating out of a number which goes from one to five, so if I have 1 I will have a star, if I have 5 I will have five stars. I can do a for loop and display the images, but I also need to show the empty ( not rated ) star. I don’t need any functionality to it, so you cannot actually rate, just show the ratings.

So because anyone is asking what I’ve tried, I haven’t tried anything because I don’t know where to begin.

I could do this to show a number of stars based on the variable I have ( which is a number from 1 -> 5 ):

<?php

$ratings = 3;

for( $i = 1; $i <= $ratings; $i++)
echo '<img src="some_image.png" />';

?>

This would be it, but what should I do for the non-rated starts, how do I display the rest of the empty stars till five ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:34:05+00:00Added an answer on June 1, 2026 at 10:34 pm

    you can do an nested for loop like so:

    $tranStars;
    
    for($i=0;$i<5;$i++){
      if($i==0){
        for($j=0;$j<$rating;$j++){
          echo "<img src='yourFullStars.png'/>";
          $tranStars=$j;
        }
        $i=$tranStars;
      }
      echo "<img src='yourEmptyStars.png'/>";
    }
    

    or you could do two separate for loops:

    for($i=0;$i<$rating;$i++){
      echo "<img src='yourFullStars.png'/>";
    }
    for($i=0;$i<5-$rating;$i++){
      echo "<img src='yourEmptyStars.png'/>";
    }
    

    … or any number of things, really.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple question, but can't seem to find a strait answer
Question very simple - say, i got function, which receives array as its arguments
My question is very simple: I have a column named DateProcessed. Whenever User Clicks
My question is very simple: In an averagely complex web request, usually we have
I have a little question very simple this time I think... How Have I
My question is very simple: Is there any solution to install xCode, or equivalent,
My question is very simple: is there any way to (programmatically, technically, or manually)
My question is very straight-forward but I could not find it on Amazon developer
My question is very fundamental, I want to know straight forward and right way
So I have a question very closely related to another question I've seen on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.