I have a kids game with a high score board. The player enters his/her name and their score is sent to a database and the top 40 scores are then shown on the game. Each score is deleted after a week.
I want to stop a few repeat players dominating the board by only displaying the top score for each of them. Thus I think I need to compare the name to be input with existing names and if there are duplicates with lower scores I wish to either delete them or change those scores to zero so that they will not be in the top 40.
My existing code is shown below. Is it possible to do the above? I have used my newbie skills on the task for the last few hours without success, probably due to an incomplete understanding of the subject.
<?php
$table="x8tables";
$keeptime=(7*24*60*60);
$user="root";
$conn=*******;
$self=$_SERVER['PHP_SELF'];
$pname=$_REQUEST['pname'];
$score=$_REQUEST['score'];
$rs=mysql_select_db("*******");
$sql="insert into $table (pname,score)values(\"$pname\",$score)";
$rs= mysql_query($sql,$conn);
$sql="select pname,score,tdate from $table order by score desc limit 40";
$rs= mysql_query($sql,$conn);
$num= mysql_num_rows($rs);
if($num >40){$num=40;};
// FLASH DATA CREATED HERE
for($i=0;$i<$num;$i++)
{echo ("pname" . $i . "=");
echo (mysql_result ($rs,$i,"pname"));
echo ("&score" . $i . "=");
echo (mysql_result ($rs,$i,"score"));
echo ("&");
}
$query="SELECT * FROM $table WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(tdate) > $keeptime";
$query="DELETE FROM $table WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(tdate) > $keeptime";
mysql_query($query);
mysql_close();
?>
Thanks
John