PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

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

Go down

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

Post by jamied_uk 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);
jamied_uk
jamied_uk
Admin

Posts : 3053
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

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

Post by jamied_uk 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.
jamied_uk
jamied_uk
Admin

Posts : 3053
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

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