This topic is locked

Spreadsheet live mode

8/11/2025 5:01:06 PM
PHPRunner General questions
Y
Yoann author

hi, i'm using the spreadsheet mode as a planning for vehicles usage, before it was on excel and the fleet managers were all working on it at the same time using the live collaboration so any change would be visible for others without having to refresh, is it something possible with php runner to use ajax to refresh automatically the cells content ?

ChatGPT 8/11/2025

PHPRunner does not natively support real-time collaboration like Excel with live updates. However, you can implement a solution using AJAX to achieve similar functionality. Here are the general steps you could follow to set this up:

  1. AJAX Setup: Use AJAX to periodically fetch the latest data from the server. You can set an interval (e.g., every few seconds) to make these requests, which will allow users to see updates made by others in real-time.


  2. Database Update: Ensure that any changes made by a user are immediately saved to the database. You can use PHP to handle form submissions and update the database accordingly.


  3. Fetch Latest Data: Create a PHP script that queries the database for the latest vehicle usage data. This script will be called by the AJAX function to refresh the spreadsheet data.


  4. Update the UI: Upon receiving the updated data from the server, use JavaScript to update the cells in your spreadsheet without requiring a full page refresh. You can manipulate the DOM to update the specific cells that have changed.


  5. Considerations for Concurrency: Since multiple users may be updating the same data, consider implementing some form of locking or version control to handle conflicts, ensuring that users are aware when data has changed and prompting them to refresh if necessary.



Here’s a simple example of how you might structure the AJAX call and response handling:

AJAX Call Example (in JavaScript)

setInterval(function() {
$.ajax({
url: 'fetch_data.php', // PHP script to fetch data
type: 'GET',
dataType: 'json',
success: function(data) {
// Update your spreadsheet cells here
updateSpreadsheet(data);
}
});
}, 5000); // Refresh every 5 seconds

PHP Script Example (fetch_data.php)

<?php
// Database connection
include 'db_connection.php';

// Fetch the latest data
$query = "SELECT * FROM vehicle_usage"; // Your query here
$result = $conn->query($query);

$data = [];
while ($row = $result->fetch_assoc()) {
$data[] = $row; // Collect data in an array
}

// Return data as JSON
echo json_encode($data);
?>

Update Spreadsheet Function

function updateSpreadsheet(data) {
// Logic to update the UI with new data
data.forEach(function(item) {
// Assuming you have a way to identify cells by some key
$('#cell_' + item.id).text(item.value);
});
}

This approach will help create a more collaborative environment similar to what your fleet managers experienced in Excel. Just keep in mind that implementing real-time updates can increase server load, so plan your interval and data handling carefully.