If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

DB Table changes notification

Started by plccourses, Sep 17, 2022, 01:09 AM

Previous topic - Next topic

plccoursesTopic starter

Greetings.

There is a database table that contains data of all the participants, both new and old. An administrator is responsible for monitoring any changes made to the table in real-time. This includes not only the appearance of new records but also their modifications. Whenever the data in the table changes, the administrator receives an alert.

To keep track of any changes made to the table, a timer can be added to JS while on the tracking page. Subsequently, a request is sent via ajax to check if there has been any modification or addition of data.

One way of checking for changes is to use SELECT to enter all records from the table into an array. After each request, the new data is compared with the old one stored in arrays. However, is there a query that signifies that the "previous query" does not match the last query, indicating a change in the table?

Perhaps a comparison between all the old data and the new ones is necessary to track any changes made to the table.
  •  

mickyrobert

To keep track of changes made to the table, one can save the time of the last creation and update of the record. The time of the last http request is also stored in JS. This enables the retrieval of records created or modified after the last request from the database.

At the end of the program, Misqli closes itself. To enable the server to send something, the use of long polling may be necessary. This entails digging in that direction.
  •  

brown.parker23

To start, you would set up a JavaScript function using `setInterval()` to execute a periodic AJAX request to the server. This function would initiate an AJAX call to a server-side script that is responsible for checking changes in the database table.

On the server side, you would create a script (e.g., in PHP, Node.js, Python, etc.) that would handle the AJAX request. This script would then execute a query on the database to retrieve the current state of the table. For example, if using PHP and MySQL, you would use the MySQLi or PDO library to perform the SELECT query and fetch the results.

Once the server-side script fetches the current database state, it would need to compare this state with the previous state to determine any changes. One approach would be to store a copy of the previous database state on the server, either in memory or in a temporary storage (e.g., a file, a separate database table, etc.).

The server-side script would then compare the current database state with the stored previous state. This comparison could involve iterating through the records in the two states and checking for differences. Alternatively, you could calculate a hash or checksum of the database state and compare it with the previous hash or checksum to determine if a change has occurred.

If a change is detected, the server-side script would then send a response back to the client-side JavaScript code indicating that a change has occurred.

Back on the client side, the JavaScript code that initiated the AJAX request would handle the server's response. If the response indicates a change, the JavaScript code could trigger an alert, update the user interface to reflect the changes, or perform any other necessary actions.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...