Jump to content

Recommended Posts

ok i need some help with this star rating system the guy wants me to add to his website, basically he wants people to be able to leave feedback along with a star rating 1-5, basic idea. now ive got the PHP all set up so far so that it inserts the "feedback" and "rating" values into a database..right now the rating is just set up as an integer(1-5)...my question is, how can i make the integer value relate to images of stars and post it for each feedback..like a rating of 1 will show 1 star image for that feedback, etc.

thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/147034-help-with-simple-star-rating-system/
Share on other sites

What about showing half stars?

 

I think on Amazon, they will go further and even show a half star

so say you have 4 1/2 stars...it would be 4 stars and a half filled star....

 

Of course you'd need to provide a "half star" image, but how do you think

the loop would be structured?

What about showing half stars?

 

I think on Amazon, they will go further and even show a half star

so say you have 4 1/2 stars...it would be 4 stars and a half filled star....

 

Of course you'd need to provide a "half star" image, but how do you think

the loop would be structured?

 

I would do it by making rating images called "0.5.gif" "1.0.gif" etc..then use the following code to echo it:

 

<?php
$rating = mysql_result(mysql_query("select rating from table where id='$id'"), 0);

echo "<img src=\"ratingimages/$rating.gif\">";
?>

 

You would just have to make sure that the ratings in the table would be in the format of 0.0 and could only be divided by 0.5, or however specific you want.

Personally, 1 to 5 with half stars is 1 to 10..

 

so rate goes upto 10!

to do the halfstar image.. just need to know what star to put on screen

<?php
$left = "leftsidestar.png"
$right = "rightsidestar.png"
//$row = array from DB containing rate
$row['rate'] = 6; //ie (from 1 to 10) (or 5 x 2)
$full = true;
for($n=0;$n<$row['rate'];$n++)
{
$img = ($full)?$left:$right;
echo "<img src='$img'>";
$full = !$full;
}
?>

 

@scarhand

While your solution is sound, it will require more images and thus more downloads and more updating if the design was changed.. these are all pretty minor so not a big deal,  however i would use 1 to 10 like star1.gif, star2.gif, star3.gif, etc because the user only see's the stars not the image names (and i think its easier not having 0.5.jpg) also the DB as you can use a tinyint. instead of a float

 

Another (fancy) option

is to create an image which is 5 stars long (max rating)

Put it inside a div and set the class overflow to hidden

now you could just workout the length..

so

5 star image is 100px thus each star is 20px or 10px per half star

now just set the div length to rate * 10

ie 3*10 = 30

so div length=30px

which makes 1 and a half stars visible!

 

the good thing about this is you can have the stars different colour or whatever! and the code doesn't change.

 

But thats going on a bit.. 101 ways to do the same thing :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.