Hiya,
Am making a rating script and what I want is, when you have already voted in the particular rating bar, you cannot rate again, it just becomes static.
In the database where I store the votes, values and IP's of the rating, in the IP row, all the IP's are serialized.
Code:
a:1:{i:0;s:14:"81.102.225.228";}
I use this query to check if my IP is already stored in the database:
PHP Code:
<?php
// Query to check if the user has voted
$voted = mysql_query(sprintf("SELECT ip FROM %s
WHERE ip LIKE '%s'
AND id = '%d'",
$table,
$ip.'%',
$id
)) or die(mysql_error());
?>
I then use this if statement to check the query:
PHP Code:
<?php
for($num = 1; $num <= $stars; $num++) {
// If the user HASN'T voted
if(!$voted) {
$image .= '
<li><a href="javascript:rate('.$num.')" title="'.$num.' out of '.$stars.'" class="star'.$num.'"> </a></li>
';
}
else {
$image .= '<li> </li>';
}
}
?>
Now when I haven't voted, I can click the rating bar, but when I have rated, I can still click it! I'm pretty sure it has something to do with the LIKE condition, and because the IP row is serialized. Can I search within the serialized code for just the IP? Or something like that...
Anyone have an idea's?
Thanks,
- Chris.