Jump to content

Help on PHP rating System

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
liri ayekpam

liri ayekpam

    Newbie

  • Members
  • Pip
  • 8 posts
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...

#2
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
What do you need help with? Do you know how to store the ratings?

#3
Guest_Jaan_*

Guest_Jaan_*
  • Guests
<?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
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
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
liri ayekpam

liri ayekpam

    Newbie

  • Members
  • Pip
  • 8 posts
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.

#6
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
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
Pa28

Pa28

    Newbie

  • Members
  • Pip
  • 4 posts

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
debtboy

debtboy

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 916 posts
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"]

#9
liri ayekpam

liri ayekpam

    Newbie

  • Members
  • Pip
  • 8 posts
Mayny thanks to all ....