I have a php script that logs inputs from a form into a mysql database table. I need a reference to only the last three inputs. To avoid the table to get filled up with inputs i'm looking for a way to insert this data untill 3 rows are created, after which it has to update the existing rows so that the first one updates to the new input, the second one to the former first input and the third one to the former second input. How can i accomplish this?
What I have tried:
i tried:$q = "select value from inputs where userid = '$userid' and name = 'input' order by id desc";
$result = mysqli_query($conn, $q);for the first three rows i can use:
if(mysqli_num_rows($result) < 4) {
$q = "insert into inputs (userid,name,value) values ('$userid','input','$value')";
}after which it has to become:
else {
$q = "update inputs set value = '$value' where userid = '$userid' and name = 'input' limit 3";
}where it has to update all the successive rows
解决方案
q = "select value from inputs where userid = '
userid' and name = 'input' order by id desc";
result = mysqli_query(