Answer the question
In order to leave comments, you need to log in
How to delete the first user entry?
There is a table with links
id user_id link
If the number of records of one user is more than 10, then delete the 1st added record and insert the 10th new record.
Something like this we get the number of records SELECT COUNT(*) FROM links WHERE user_id=43
Check in php
if($count <= 5)
{
//sql insert
}else{
//sql insert
$links_id_arr = ['3', '14', '35', '10', '43' , '23'];
//Находим самый маленкий ИД в $links_id_arr
$min_in_arr = 3;
$sql = "DELETE FROM links WHERE user_id=43 AND id= $min_in_arr";
}
Answer the question
In order to leave comments, you need to log in
if it’s stupid in the forehead, then the
first query is count and delete with a lower id if count = 10
the second is inserted
if it’s smart, then the field with the date of creation / update of the record would not interfere and then everything can be done in one query with if
, well, and you are really sure that it is necessary delete?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question