Collegize Posted October 8, 2010 Share Posted October 8, 2010 Ok, so on my website I have a rating script, simple right? It's a five star rating script and anyone can 5 star rate. For example: Student Popularity: 5 Stars --- Ok, so that's cool right, you can rate people! No not really. Each rating goes the same on every single persons profile. If I rate someone, it goes and rates every other user the same rating. Is there anything I can do with MYSQL to have the ratings different for each member? Quote Link to comment https://forums.phpfreaks.com/topic/215391-help-with-rating-script/ Share on other sites More sharing options...
BlueSkyIS Posted October 8, 2010 Share Posted October 8, 2010 each member must have a unique id. then you update rating for the specific id. Quote Link to comment https://forums.phpfreaks.com/topic/215391-help-with-rating-script/#findComment-1120071 Share on other sites More sharing options...
Collegize Posted October 8, 2010 Author Share Posted October 8, 2010 Each member has a unique ID because it's a social network. But where to I put the unique ID in? This is my SQL for the rating script: CREATE TABLE `rating` ( `ip` varchar(15) NOT NULL, `rating` varchar(1) NOT NULL, `page` varchar(99) NOT NULL, PRIMARY KEY (`ip`,`page`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; and this is my php code for my rating script: <? include("constants.php"); $action = $_GET['a']; if($action==1) { rate(); } if($action==2) { reRate(); } function rate() { $star_value = $_GET['r']; $page = $_GET['p']; $ip = $_SERVER['REMOTE_ADDR']; //Add to database mysql_query("INSERT INTO `".DB_TABLE."` VALUES ('$ip','$star_value','$page')"); $ref = $_SERVER['HTTP_REFERER']; header("Location: " .$ref); } function reRate() { $star_value = $_GET['r']; $page = $_GET['p']; $ip = $_SERVER['REMOTE_ADDR']; //Add to database mysql_query("UPDATE `".DB_TABLE."` SET `rating` = '$star_value' WHERE `ip` = '$ip' AND `page` = '$page'"); $ref = $_SERVER['HTTP_REFERER']; header("Location: " .$ref); } function writeRate($page) { $ip = $_SERVER['REMOTE_ADDR']; $result = mysql_query("SELECT `ip` FROM `".DB_TABLE."` WHERE `ip` = '".$ip."' AND `page` = '$page'"); $num_rows = mysql_num_rows($result); if($num_rows==1) { echo '<p>Your Rating: '; $result = mysql_query("SELECT `rating` FROM `".DB_TABLE."` WHERE `ip` = '".$ip."' AND `page` = '$page'"); $rating = mysql_result($result, 0); if($rating == 1) { echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a>'; } if($rating == 2) { echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackTwo(\''.$page.'\')" /></a>'; } if($rating == 3) { echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackThree(\''.$page.'\')" /></a>'; } if($rating == 4) { echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackFour(\''.$page.'\')" /></a>'; } if($rating == 5) { echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackFive(\''.$page.'\')" /></a>'; } echo '<br>'; } else { echo '<p>Your Rating: '; echo ' <a href="include/rate.php?p='.$page.'&r=1&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=1"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBack(\''.$page.'\')" /></a>'; echo '<br>'; } $result = mysql_query("SELECT `rating` FROM `".DB_TABLE."` WHERE `page` = '".$page."'"); $num_rows = mysql_num_rows($result); $i=0; $star_value = 0; while($i<$num_rows) { $rating = mysql_result($result,$i); $star_value = $star_value + $rating; $i++; } if($star_value==0) { $avg_value = 0; } else { $avg_value = $star_value / $num_rows; } //Assign Value if ($avg_value <= 0 ){$rater_stars = "stars/00star.gif";} if ($avg_value >= 0.5){$rater_stars = "stars/05star.gif";} if ($avg_value >= 1 ){$rater_stars = "stars/1star.gif";} if ($avg_value >= 1.5){$rater_stars = "stars/15star.gif";} if ($avg_value >= 2 ){$rater_stars = "stars/2star.gif";} if ($avg_value >= 2.5){$rater_stars = "stars/25star.gif";} if ($avg_value >= 3 ){$rater_stars = "stars/3star.gif";} if ($avg_value >= 3.5){$rater_stars = "stars/35star.gif";} if ($avg_value >= 4 ){$rater_stars = "stars/4star.gif";} if ($avg_value >= 4.5){$rater_stars = "stars/45star.gif";} if ($avg_value >= 5 ){$rater_stars = "stars/5star.gif";} echo 'Avg Rating: <img src="'.$rater_stars.'" width="80" height="16" border="0" name="Rate"/>'; echo '<br>'; echo $num_rows." Ratings (Avg ".substr($avg_value,0,4).")"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/215391-help-with-rating-script/#findComment-1120072 Share on other sites More sharing options...
fenway Posted October 8, 2010 Share Posted October 8, 2010 I don't understand what you're trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/215391-help-with-rating-script/#findComment-1120180 Share on other sites More sharing options...
Collegize Posted October 8, 2010 Author Share Posted October 8, 2010 I'm trying to make it so each user has their own ratings. If I leave it the way it is and I rate someone out of 5 stars, it rates everyone else out of 5 stars too. So everyone has the same ratings. I want it so everyone has individual ratings. Quote Link to comment https://forums.phpfreaks.com/topic/215391-help-with-rating-script/#findComment-1120227 Share on other sites More sharing options...
BlueSkyIS Posted October 8, 2010 Share Posted October 8, 2010 you need a column in the rating table for member_id, or whatever. store the member_id there so each record is tied to an individual record. Quote Link to comment https://forums.phpfreaks.com/topic/215391-help-with-rating-script/#findComment-1120235 Share on other sites More sharing options...
Collegize Posted October 8, 2010 Author Share Posted October 8, 2010 Ok, will I have to change up the PHP script @ all? Quote Link to comment https://forums.phpfreaks.com/topic/215391-help-with-rating-script/#findComment-1120237 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.