如何检查表的内容是否已使用php和mysql进行更新

如何检查表的内容是否已使用php和mysql进行更新

问题描述:

Is their anyway of checking whether data has been entered into the table and then displaying the updated data as soon as it is updated ??

他们无论如何都要检查是否已将数据输入表中,然后一旦显示更新的数据 更新?? p> div>

What I can understand is that you are working for a Client-Server Message project.

You need to create a column for the timestamps in MySQL named anything like 'timestamp' and everytime you enter a entry in the table, for example a chat table, you need to insert the timestamp there in the same query.

In php you can use time() to get the current timestamp. You can set your timezone using this : date_default_timezone_set(), PHP timezones.

And save a variable which saves the last time retreived from the database. Send that with the query to the server.

Return the client all the messages based on the timestamp.

Use mysqli_error() to check, if this returns false you know the INSERT ran as you intended.

mysqli_query($conn,"INSERT INTO mytable (`columnone`,`columntwo`,`columnthree`) 
VALUES ('$valueone','$valuetwo','$valuethree')") 
or die(mysqli_error($db));

Now run a SELECT query to find the item you just inserted, and return it. Simple!

If you want all this to happen without reloading the page, use AJAX and return the result of the SELECT query upon successful submission.

If I understand you correctly I think you need to store a timestamp for every update and insert (or one for both). Just add a column to each table (I usually call it 'ts'). You can even make it update automatically: https://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html

Edit: then you can obviously use that column to select the most recently updated row, see if anything's changed in X amount of time etc etc