Hello,
I want know that how we can rate a specific item, when we search in website.
I tried rating with options 1,2,3,4,5 using drop down boxes. But I couldn't know how to rate for each item and to store the rating value for that item.
My code does simple rating, but the rating value for that item should be stored in database. I mean to say that when I rate some particular item, the rating value and corresponding rated item's name should be stored in the database.
This is my code,
<?php
$dbhost = "localhost"; // this will ususally be 'localhost', but can sometimes differ
$dbname = "users"; // the name of the database that you are going to use for this project
$dbuser = "root"; // the username that you created, or were given, to access your database
$dbpass = ""; // the password that you created, or were given, to access your database
mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
$itemid = mysql_real_escape_string($POST["item_id"]);
$rating = intval($POST["rating"]);
if(($rating < 1)||($rating>5)) die ("$rating is not a valid rating score");
$query = "INSERT INTO ratings(item_id,rating) VALUES ('$itemid',$rating)";
mysql_query($query);
$query = "SELECT item_id,AVG(rating) FROM ratings GROUP BY item_id";
$result = mysql_query($query);
while($values = mysql_fetch_row($result)){
$itemid = $values[0];
$rating = number_format($values[1], 2, '.', '');
echo "Thank you for rating this project...";
}
?>
And the following is my php code which is included in search script,
echo '<form method="post" action="store_rating.php">';
echo '<input type="hidden" name="item_id" value="project">';
echo'<select name="rating">';
echo'<option value="1">1</option>';
echo'<option value="2">2</option>';
echo'<option value="3">3</option>';
echo'<option value="4">4</option>';
echo'<option value="5">5</option>';
echo'</select>';
echo'<input type="submit" value="Rate This">';
echo'</form>';
Can u please help me in this context...