There is a very easy way to do this using a MySql myisam table. Store each vote in a table like this...
CREATE TABLE `vote` (
`username` varchar(50) NOT NULL,
`vote_year` year(4) NOT NULL,
`week_num` tinyint(4) NOT NULL,
`vote_count` int(11) NOT NULL AUTO_INCREMENT,
`time_voted` datetime DEFAULT CURRENT_TIMESTAMP,
`voted_for` int(11) DEFAULT NULL COMMENT 'Who/whatever was voted for',
PRIMARY KEY (`username`,`vote_year`,`week_num`,`vote_count`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Note the last column of the primary key is the auto-increment column "vote_count". This will make the vote count start again at 1 for each username each week whe you add votes.
mysql> INSERT INTO vote (username, vote_year, week_num, voted_for) VALUES
-> ('user1', year(curdate()), weekofyear(curdate()), 1),
-> ('user1', year(curdate()), weekofyear(curdate()), 20),
-> ('user1', year(curdate()), weekofyear(curdate()), 5),
-> ('user2', year(curdate()), weekofyear(curdate()), 5),
-> ('user2', year(curdate()), weekofyear(curdate()), 1),
-> ('user2', year(curdate()), weekofyear(curdate()), 3);
Query OK, 6 rows affected (0.00 sec)
mysql> select * from vote;
+----------+-----------+----------+------------+---------------------+-----------+
| username | vote_year | week_num | vote_count | time_voted | voted_for |
+----------+-----------+----------+------------+---------------------+-----------+
| user1 | 2021 | 24 | 1 | 2021-06-16 17:37:56 | 1 |
| user1 | 2021 | 24 | 2 | 2021-06-16 17:37:56 | 20 |
| user1 | 2021 | 24 | 3 | 2021-06-16 17:37:56 | 5 |
| user2 | 2021 | 24 | 1 | 2021-06-16 17:37:56 | 5 |
| user2 | 2021 | 24 | 2 | 2021-06-16 17:37:56 | 1 |
| user2 | 2021 | 24 | 3 | 2021-06-16 17:37:56 | 3 |
+----------+-----------+----------+------------+---------------------+-----------+
6 rows in set (0.00 sec)
To do the insert in PHP
$stmt = $pdo->prepare("INSERT INTO vote (username, vote_year, week_num, voted_for)
VALUES
( ?, year(curdate()), weekofyear(curdate()), ? )
");
$stmt->execute( [ $username, $votedFor ] );
Now it doesn't matter how many times a user votes. When you come to counting the votes for each "voted_for" just ignore all records whose vote_count is > 10
SELECT voted_for
, count(*) as votes
FROM vote
WHERE vote_count <= 10
GROUP BY voted_for
ORDER BY votes DESC