How to realize the record of PHP's winning streak or losing streak?

the application situation is like this.
you need to record your daily winning streak or losing streak. You need to re-zero and recalculate whenever you win or lose.

uses MYSQL but doesn"t know how to design the table segment. Ask for help

Php
Mar.02,2021

this and daily check-in is a business logic
1) A user id
2) the number of times of a winning or losing streak
3) an latest status (win or lose)
4) time
problem solving


it is best to create a separate table, for example, call the winscount, field: id, userid, wins, time
look up the previous winscount record based on whether the game is won or not. If wins is less than 0, it is a losing streak, and a winning streak greater than 0.
the latest winscount record after a victory with a wins greater than 0 means a winning streak. If the latest winscount record with a wins greater than 0 after the defeat of wins+1,
, the winning streak is interrupted, a new record with a wins of-1 is created.
if the latest winscount record wins is less than 0 after a failure, if the wins-1, is greater than 0, the failure sequence is interrupted, and a new winscount record wins=1 is created

wins you can split it into two fields, one number and one indicating victory or defeat.
this is an idea, which can be used for reference, and the details can be optimized and perfected. Another advantage of this design is that it can trace the historical record, such as the highest winning streak of the year, the highest winning streak of the quarter.
aside, I don't think the winning streak should be limited on a day-to-day basis.


you can use a field to record the number of games in a row, and a field to record the time of victory / defeat, and then the program first determines that if one day has passed, the number of games in a row is set to 0, and then determines that if you win, the number of games in a row is + 1, and if you lose, you can clear 0; add a table to store the record of victory or defeat.


there should be a user list, user challenge (or competition) record table, and then record the winning streak. Think about the specific fields of the record table.


try redis?
K (uid "Mark user) + V (bool record") Storage record;
every time the result is generated, in addition to updating the field data in mysql, the value in redis is added to one, the winning game returns to zero, and the negative field returns to zero, and vice versa.
then persist the data at the end of each day.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea7d05-1e88.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea7d05-1e88.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?