unfortunately I have not found anything yet, maybe anyone could help me or give me a hint?
I have a table called “users” and a field “last_login” where I want to store the login dates of the last let’s say 30 logins. So, each time the user logs in successfully, the timestamp should be added at the end of the string, so it looks sth like this:
logdindate1;logindate2;logindate3;…
..whereas logindates are timestamps with a certain size. However, if we reach logindate31, logindate1 should be deleted and logindate31 added at the end.
Is there any way to do that very easily within the MySQL query or do I have to check length with php? If yes, will I need a SELECT, then check the length, cut it and then a separate UPDATE? Or is there any better way to do it at all?
The query I have till now is (it does not check the length or cut anything):
<?php $query = "UPDATE user SET login_date = CONCAT(login_date,'".$logindate.";') WHERE id='".$user_id."';"; ?>
Thank you very much in advance!
Create a table login_history and insert the new login date there. Use a JOIN to retrieve the login dates of a user.
I strongly recommend you get a basic understanding of what’s called “Database normalization”