I am attempting to build a rating script with a slight twist. Rather than having pictures rated 1-10 pictures will be rated via a % of the number of times it was rated.
I’ve created the form to do it, however, I’m unsure how to proceed with the PHP. Shown below is the code for the form:
Any help would be great. :o)
<form action=rate.php method=post />
<p>
<label>
<input type=radio name=rate value=1 id=RadioGroup1_0 />
I Like Yours</label>
<br />
<label>
<input type=radio name=rate value=0 id=RadioGroup1_1 />
I Don't Like Yours</label><br />
<input type=submit name=submit value=Rate />
<br />
</p>
</form>
You will need to create a database to store the data, restrict how many times an individual may vote (i.p. restricted? per user?), perform math on the data as you see fit, then output the data as you like
Ok, thank you, therefore I’m assuming I’m going to need use While loops and some form of array to make it fully work. I can get it to do the simple part i.e. work out the percentage but the rest is a blur.
I’ve assigned the value of 1 to one radio button and 0 to the other when a user votes for 1 it needs to be added, would this be a for loop?
Sorry to ask so many questions I know some of the basics but not all.
Here’s a script I’ve come up with for it, however it doesn’t seem to update the votes to include a new vote from the form. It works out the rating fine, just not add new votes to the database.
I’m using radio buttons any help?
<?php
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("cystem_ilikeyours") or die(mysql_error());
// Get the radio button values
$vote = $_POST['vote'];
// Convert the values to the actual name, if you like
switch($vote) {
case '1':
$vote = "+1";
break;
case '0':
$vote = "0";
break;
}
// Update the data
$updat_array = mysql_query("UPDATE 'co_rate' WHERE rate_id = '1'");
// Put it into an array
$array = mysql_query("SELECT * FROM co_rate ")
or die (mysql_error());
// Loop Through the data
while ($rate = mysql_fetch_array($array)) {
//This calculates the sites ranking and then outputs it - rounded to 1 decimal
$current = $rate[votes] + $rate[votes] / $rate[total];
echo "Current Rating: " . round($current, 2) . "<br>";
}
// One vote per user
// Add the total number votes up
// Work out the percentage
// Display the result as a percentage
?>