I want to put a rating system on my website. I am requesting help from your side. It will work as follows
I have 5 programs listed using radio buttons under the heading Favorite Programs where user will select one from them. The count of which will be maintain in the database. Using that total count of each program rating will be given to that particular program
Like if the count is more than
10 and less than 40, 1 star should be given
41 and less than 80, 2 star should be given
81 and less than 100, 3 star should be given
101 and less than 120 4 star should be given
121 and more, 5 star should be given
eagerly waiting for replies...
Help on PHP rating System
Started by liri ayekpam, Oct 03 2009 01:59 PM
8 replies to this topic
#1
Posted 03 October 2009 - 01:59 PM
|
|
|
#2
Posted 03 October 2009 - 02:25 PM
What do you need help with? Do you know how to store the ratings?
#3
Guest_Jaan_*
Posted 03 October 2009 - 02:25 PM
Guest_Jaan_*
<?php
$num = 1;
$rating = 95;
while($num<=$rating){
if($rating>=10 and $rating<=40){
echo "X";
break;
}elseif($rating>=41 and $rating<=80){
echo "X X";
break;
}elseif($rating>=81 and $rating<=100){
echo "X X X";
break;
}elseif($rating>=101 and $rating<=120){
echo "X X X X";
break;
}elseif($rating>=120){
echo "X X X X X";
break;
}
$num++;
}
?>
well that should do the trick
#4
Posted 03 October 2009 - 03:33 PM
You may want to round($rating) to force $rating to be an integer as the code above is undefined 40 < $rating < 41, 80 < $rating < 81, and 100 < $rating < 101.
#5
Posted 04 October 2009 - 08:59 PM
Thanks for the immediate reply.
Well that's O.K. giving rating as XXXXX but I would like to give rating as we generally give by stars image. Do we have another optioin.
Well that's O.K. giving rating as XXXXX but I would like to give rating as we generally give by stars image. Do we have another optioin.
#6
Posted 04 October 2009 - 10:03 PM
replace the X with a tiny star image :D
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript
#7
Posted 05 October 2009 - 11:32 AM
John said:
You may want to round($rating) to force $rating to be an integer as the code above is undefined 40 < $rating < 41, 80 < $rating < 81, and 100 < $rating < 101.
Or just adjust the conditions in the if statements:
<?php
$rating = 95;
function echoStars($count) {
$starImage = "<img src=\"star.jpg\" />";
for($i=0;$i<$count;$i++)
echo($starImage);
}
if($rating>=10){
if($rating<=40){
echoStars(1);
}elseif($rating<=80){
echoStars(2);
}elseif($rating<=100){
echoStars(3);
}elseif($rating<=120){
echoStars(4);
}else{
echoStars(5);
}
}
?>
Edited by Pa28, 05 October 2009 - 02:28 PM.
#8
Posted 05 October 2009 - 03:31 PM
You'll also want to collect and keep track of some
request server variables to prevent the same person
from voting over and over again.
This info should be kept in a database, but you could
also plant an already voted cookie on them, assuming
the don't clear their cookies.
You will need these and maybe some more:
$ip = $_SERVER["REMOTE_ADDR"]
$ip_forward = $_SERVER["HTTP_X_FORWARDED_FOR"]
request server variables to prevent the same person
from voting over and over again.
This info should be kept in a database, but you could
also plant an already voted cookie on them, assuming
the don't clear their cookies.
You will need these and maybe some more:
$ip = $_SERVER["REMOTE_ADDR"]
$ip_forward = $_SERVER["HTTP_X_FORWARDED_FOR"]
#9
Posted 06 October 2009 - 12:53 PM
Mayny thanks to all ....


Sign In
Create Account

Back to top









