how to remove old scores from database for game high score tables

View previous topic View next topic Go down

how to remove old scores from database for game high score tables

Post by jamied_uk on 16th November 2013, 01:46

Code:
$con=mysqli_connect("localhost","root","password","database");
$count = mysqli_query($con,"SELECT * FROM highscores WHERE username = '$username'");

$count_check = mysqli_num_rows($count);
$new_count = $count_check - "1";
$new_count = "LIMIT $new_count";

mysqli_close($con);

$con=mysqli_connect("localhost","root","password","database");
mysqli_query($con,"DELETE FROM highscores WHERE username = '$username' ORDER BY score ASC $new_count");
mysqli_close($con);
avatar
jamied_uk
Admin

Posts : 2155
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: how to remove old scores from database for game high score tables

Post by jamied_uk on 16th November 2013, 01:51

This script will count how many rows are in use for the currently logged in user

then it will delete all rows except the highest score for that user,

so i recommend inserting into the highscores table the newest high score first before deleting any rows that contain the lowest scores,


then this will only remove the rows with a less score and can be modified so that it can remove before inserting a new score but this is not recommended in case the lesser score is removed by accident!


you can also use ASC in your sql if it removes the wrong score so test this out and have fun, any comments please post here.


Please visit jnetscripts.com and tell all your friends about it, my name on there is multimedia.
avatar
jamied_uk
Admin

Posts : 2155
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum