I think the problem is the while statement when performing the query. If im correct, you cannot get a value from an a attribute. Put in a hidden input field or just put the id in the function as below. If you use the input, take out r in the function and use the previous function that was provided, but i think that putting the id in the function name () and calling the function with a variable will work better.
Change:
while($row = mysql_fetch_array($result) { echo "<img src='".$row['filepath']."'>"; echo "<br>"; echo "<a id='".$row['id']."' value='".$row['id']."' onclick='getrating();'>Likes: ".$row['likes']."</a>"; echo "<br>";}while($row = mysql_fetch_array($result) {
echo "<img src='".$row['filepath']."'>";
echo "<br>";
echo "<a onclick='getrating('".$row['id']."');'>Likes: ".$row['likes']."</a>";
//echo "<input type='hidden' id='".$row['id']."' value='".$row['id']."' />";
echo "<br>";
}
If the onclick doesnt work, tak out the '' from the '".$row."'.
Then in our function:
function getrating(r) {
document.getElementyById(r).value;
alert(r);
}