I use date("h:i:s")
for example. I've tried to execute the update query to multiple databases at same time, but the time could be different 1 or 2 seconds. I wonder if there were another ways to execute it at same time..
this is my script
<script type="text/javascript">
<!--
function updateTimer() {
var db = "1,2,",
dbindex = db.split(","),
countdb = 2;
function retrieve(id) {
if(id < countdb) {
$.ajax({
url: 'update.php',
type: 'post',
data: {
idx : dbindex[id]-1
},
success: function (output) {
id++;
retrieve(id);
},
error: function () {
alert("Error Update");
}
});
}
}
retrieve(0);
}
//-->
</script>
update.php
$idx = $_POST["idx"];
$conn = $db[$index[$idx]]; // testdb and test2db
$timer = date("h:i:s");
mysqli_query($conn,"update table set timer='".$timer."'");
Yes. You can send in POST an array of DB_ids;
function retrieve(id) {
data = [];
for(;id<countdb;id++)
{
data.push(dbindex[id]-1)
}
$.ajax({
url: 'update.php',
type: 'post',
data: {
idx : data
},
success: function (output) {
alert("Ok!");
},
error: function () {
alert("Error Update");
}
});
}
if(isset($_POST["idx"])){
$idx = $_POST["idx"];
foreach($idx as $id){
$conn = $db[$index[$id]]; // testdb and test2db
$timer = date("h:i:s");
mysqli_query($conn,"update table set timer='".$timer."'");
}
}
But You need to make some validation.