Sythe.Org Forums     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe.Org Forums  
   Runescape Gold

Sythe.org — A Virtual Goods Trading Hub

Make real cash! buying and selling in-game items.

We have a no-scam policy.

You can make thousands playing your favourite games here at Sythe.org.

Just sign up an account and follow the rules!


Take me to

Runescape Markets

Other Game Markets

Support Center

Register an Account

Close
[PHP] Creating a simple Rating System [Easy]
 
 
LinkBack Thread Tools Display Modes
  #1  
Old 09-28-2010, 10:01 AM
Forum Addict
BANNED
 
Join Date: Jan 2009
Location: Georgia.
Posts: 620
Default [PHP] Creating a simple Rating System [Easy]

Hey guys, thanks for coming, in this tutorial I will show you how to create a basic and simple to use rating system. I hope it helps ya.

The basics

We divide the task into the following steps:
  • Display a HTML form where a visitor can select a rating.
  • Read the existing results
  • Check if the actual IP exists among the old results
  • Add valid rating to the result list
  • Display the actual rating


Displaying the HTML form

This is an easy part. As usually we create a normal HTML form which is displayed during the first call of the script. As the script itself contains the processing part as well we first check if we really need to display the form or process the submitted data. So the first part of the code looks like this:

Your rating: 1 2 3 4 5


Reading the Existing Results

For the next step we need to process the user input. In this step we initialize some variables to store total ratings, total points, and last, but not least, actual rating. This is quite simple:

Quote:
$rate = isset ($_POST['rate']) ? $_POST['rate'] : 0;
$filename = "ratings";
$alreadyRated = false;
$totalRates = 0;
$totalPoints = 0;

$ip = getenv('REMOTE_ADDR');
?>
IP Obtaining, locking in ratings.
Afterwards we retrieve the actual user IP. Later we will check if this IP is already saved in the result list. If there is already a result from the actual IP, then we'll ignore the new one. With this solution we can avoid manipulations of our ratings. So, we need to open the result file and read it into an array using the "file" function. Next, we iterate over this array and summarize the ratings until now. Of course we also check the IP, below will be the coding used for such:

Code:
// Read the result file
$oldResults = file('results/'.$filename.'.txt');

// Summarize total points and rates
foreach ($oldResults as $value) {
$oneRate = explode(':',$value);
// If our IP is in the list then set the falg
if ($ip == $oneRate[0]) $alreadyRated = true;
$totalRates++;
$totalPoints += $oneRate[1];
}
?>
Now, if the rating seems to be valid then we open the result file again and append a new result entry at the end of the file with the actual user IP. Besides this we update the total rating points we have collected in the previous step.


The Final Stages:
Lastly, what we want to do is only display the actual rating. We can do that with only displaying the value or we can displaying some graphics like stars to make it a bit nicer.


Code:
echo "Actual rating from $totalRates rates is: "
.substr(($totalPoints/$totalRates),0,3)."
";

// Display the actual rating
for ($i=0;$i<round(($totalPoints/$totalRates),0);$i++){
echo "";
}
?>

Thanks for viewing my tutorial, if you liked this one, don't forget to check out my other tutorials including:
  #2  
Old 09-29-2010, 10:16 AM
Forum Addict
BANNED
 
Join Date: Sep 2010
Posts: 267
Default Re: [PHP] Creating a simple Rating System [Easy]

Another greatly detailed and easy to read guide.

I enjoy reading them(Even if I know what you're explaining!).

Keep 'em coming, dude!
  #3  
Old 09-29-2010, 03:37 PM
Forum Addict
BANNED
 
Join Date: Jan 2009
Location: Georgia.
Posts: 620
Default Re: [PHP] Creating a simple Rating System [Easy]

Quote:
Originally Posted by Liquid_stranger View Post
Another greatly detailed and easy to read guide.

I enjoy reading them(Even if I know what you're explaining!).

Keep 'em coming, dude!
Hehe thank you.


I've posted these on a few sites and got some good replies. It's what makes me write more . And the fact I enjoy helping others.

Glad I helped you!
  #4  
Old 09-29-2010, 03:55 PM
Mr Smith's Avatar
'It's not over 'till the fat lady sings' - Remember that.
$100 USD Donor New
 
Join Date: Aug 2010
Location: Newcastle Upon Tyne
Posts: 875
Default Re: [PHP] Creating a simple Rating System [Easy]

Great guide, I learn new stuff everyday, thanks.
  #5  
Old 10-07-2010, 11:07 AM
Dr. James's Avatar
Active Member
$5 USD Donor New
 
Join Date: Sep 2010
Posts: 120
Default Re: [PHP] Creating a simple Rating System [Easy]

Ripped you fag.
__________________
How donor ranks == trustworthiness.
A donor has donated 50 dollars, should you trust him with 5/10 dollars? Yes, despite what people say on here, ranks are trustworthiness. Why scam a trivial 10 dollars? If you're willing to let go 50?
  #6  
Old 10-07-2010, 11:37 AM
Persia_Ugly's Avatar
Grand Master
$5 USD Donor
 
Join Date: Aug 2008
Location: North America
Posts: 2,499
Default Re: [PHP] Creating a simple Rating System [Easy]

I agree this seems ripped, unless your the admin of the website I seen it on, which I doubt.

edit:lol its word for word
__________________

Last edited by Persia_Ugly : 10-07-2010 at 11:37 AM.
 



Cheap RS Gold Store  Runescape Gold

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 08:02 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1