Reputation: 1701
I have a table that stores feedbacks about tutors and the rating (out of 5) which other users give them.
Following is my code where I fetch data from database:
<?php foreach ($tut_feedback as $tf) { ?>
<div class="">
<h4 class="title"><strong><?php echo $tf->std_name;</strong></h4>
<span class="meta"><?php echo $tf->newdate_time; ?></span>
<span class="rating"><?php echo $tf->tutor_rating; ?></span> // display numbers like 2,3,4
<p class="description"><?php echo $tf->feedback_description; ?></p>
</div>
<?php } ?>
My question is how can I display the numbers as stars. For example, if a tutor has rating of 4, I want to display 4 stars instead of the number..
Upvotes: 2
Views: 2100
Reputation: 1097
Based on the tutor rating you can run one for loop:-
$rating = $tf->tutor_rating;
for($i=0; $i<$rating; $i++) {
echo "<img src='star.png' alt='*'>";
}
Upvotes: 4