visualazza Posted March 19, 2010 Share Posted March 19, 2010 hi, im have many rows in a database with one column called rating. I am trying to think of a way to allow a user to rate a file but not be able to rate that file again, but still be able to rate other files they have not rated yet. Basically i would use the update query to rate the file but how would i go about banning the ip address for that row in the db Thanks Link to comment https://forums.phpfreaks.com/topic/195798-rating-system-with-ip-addresses/ Share on other sites More sharing options...
Jax2 Posted March 19, 2010 Share Posted March 19, 2010 You need a second table called "ratings" ... you would set it up something like this: ID (of item being rated) IP (of person doing the rating) so when they rate something, you store their rating in the main table, but you also add their IP address and the ID of the item they rated to the second table. Then, in your rating script, have it check the second table for the ID number of the item... if it finds the same IP address with the same ID number, tell it to return a negative - as in, you already voted on this. It works Link to comment https://forums.phpfreaks.com/topic/195798-rating-system-with-ip-addresses/#findComment-1028558 Share on other sites More sharing options...
visualazza Posted March 19, 2010 Author Share Posted March 19, 2010 yeah just after i posted i thought about that. Would querying 4 tables in one script cause any problems? Thanks for your help and quick reply. Link to comment https://forums.phpfreaks.com/topic/195798-rating-system-with-ip-addresses/#findComment-1028559 Share on other sites More sharing options...
Jax2 Posted March 19, 2010 Share Posted March 19, 2010 NP... I leave your second question up to someone else though, I am having a tough time myself with joining tables (Have a question on here right before yours lol) ... and that's only with 2 tables. Link to comment https://forums.phpfreaks.com/topic/195798-rating-system-with-ip-addresses/#findComment-1028562 Share on other sites More sharing options...
visualazza Posted March 19, 2010 Author Share Posted March 19, 2010 ok, i quickly did this but i does not work. $id = $row['id']; $ip=@$REMOTE_ADDR; $qry = "SELECT * FROM ratings WHERE id='$id' AND ip='$ip'"; $result = mysql_query($qry) or die(mysql_error()); if($result) { if(mysql_num_rows($result) == 1) { echo("You have already rated"); }else { echo("<form action=rate.php method=POST><input type=text value=5 size=1 width=1 name=vote maxlength=1><input type=submit value=Go></form>"); } } in my ratings table i have id (of the file) and ip (of a rated user) this should find out if the current users ip address has been added in the db for that file Link to comment https://forums.phpfreaks.com/topic/195798-rating-system-with-ip-addresses/#findComment-1028572 Share on other sites More sharing options...
Jax2 Posted March 19, 2010 Share Posted March 19, 2010 Oops never mind lol ... try this? if(mysql_num_rows(mysql_query("SELECT * FROM ratings WHERE id = '$id' and where ip= '$ip'"))){ echo "You have already voted."; } Link to comment https://forums.phpfreaks.com/topic/195798-rating-system-with-ip-addresses/#findComment-1028583 Share on other sites More sharing options...
visualazza Posted March 19, 2010 Author Share Posted March 19, 2010 sorry but it doesnt seem to work Link to comment https://forums.phpfreaks.com/topic/195798-rating-system-with-ip-addresses/#findComment-1028602 Share on other sites More sharing options...
visualazza Posted March 19, 2010 Author Share Posted March 19, 2010 im managed to solve it myself. It wasnt getting the ip address for some reason. In the end i realised as only users can vote ill just make it so it gets the username from the session instead. Thanks to Jax2 for all his help. Link to comment https://forums.phpfreaks.com/topic/195798-rating-system-with-ip-addresses/#findComment-1028630 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.