PDA

View Full Version : PHP - Rating Script



Damoose
June 6th, 2002, 09:06
Anyone willing to help me for free? Because im only 13 i am not able to pay for someone to write a script.

My site is http://www.companyreviews.net and I want visitors to be able to rate the sites by selecting from 1 to 5, anyone help me? Thankyou so much.

chuongac
June 6th, 2002, 10:04
check here friends
it is free php script

http://www.onlinetools.org/tools/easyranks.php

good luck:D

Damoose
June 6th, 2002, 11:45
thanx so much, ill try it out :)

Christopher
June 6th, 2002, 14:38
Well, if you have a database it is quite easy. If you already know some PHP that is.

Just make sure you have a column in your database, lets say you named it "rate."

Make a form similar to this:


<form action="action_page.php" method="post">
<input type="radio" name="rating" value="1">1<br>
<input type="radio" name="rating" value="2">2<br>
<input type="radio" name="rating" value="3">3<br>
<input type="radio" name="rating" value="4">4<br>
<input type="radio" name="rating" value="5">5<br>
<input type="submit" value="Vote">
</form>

Then in your action page, do a scrip similar to this (you will have to aquire the old value of "rate" in your database...)


<?php
mysql_connect("yourserver","yourdatabase","yourpassword") or die("An error occurred.");
mysql_select_db("yourdatabase");

$get_old = mysql_query("SELECT rate FROM yourtable");
$old_data = mysql_fetch_array($get_old);

$old = $old_data[rate]; // Gets the value (number) of "rate"
$new = ($old + $rating) / 2 // "$rating" is from the form, the math is to figure out the average

mysql_query("UPDATE yourtable SET rate=$new") or die("An error occurred"); //Updating the new average.
?>

Of coarse, if you want to rate different things, you just alter the first mysql query to
$get_old = mysql_query("SELECT rate FROM yourtable WHERE sitename='sitename'");, thats if you have a column with the site name you want to rate...

You might want to look over the syntax, I probably made a mistake.