Reputation: 3
I want to make a mysql query after a few seconds the website user has performed an action on my website. I think I can do it with php sleep, but i don't know if it is the best way to do it. What are the options for doing that? Thanks for your answers.
Edited:
The idea is: I have a lobby, where website registered users can join (When they join a mysql query is performed updating the info on their sql row, setting that they are connected to lobby number x, and on slot x, but they aren't joined to the server). When they join to the lobby i want to give them x time (suppose 5 minutes) to join a counter strike source server (This updates the user row setting that they are joined to the server). But, i want to kick them of the lobby (this is just updating again their row in the mysql database), if in those 5 minutes they haven't joined the server. I got all of this coded except the part of wait 5 minutes and check if they are connected.
The code is:
$PlayerSlot=mysql_real_escape_string($_POST['playern']);
$sID = mysql_real_escape_string($_POST['jsID']);
//Check if actual player is already in another lobby
$query = sprintf("SELECT `playern` FROM `WebsiteUsers` WHERE `userID`='%s'", mysql_real_escape_string($_SESSION['userID']));
$result = mysql_query($query, $con) or die("Error checking user state: ".mysql_error());
$row = mysql_fetch_row($result);
$playerPlaying = $row[0];
//Check if the slot is free
$query = "SELECT `".$PlayerSlot."` FROM `ServerPlayers`";
$result = mysql_query($query, $con);
$PlayerSlotFree = mysql_fetch_row($result);
if($playerPlaying == NULL && $PlayerSlotFree[0] == NULL) {
$query = "UPDATE `WebsiteUsers` SET `playern`='".$PlayerSlot."', `servern`='".$sID."' WHERE `userID`='".$_SESSION['userID']."'";
$result = mysql_query($query, $con) or die(mysql_error());
$query = "UPDATE `ServerPlayers`SET `".$PlayerSlot."`='".$_SESSION['userID']."', WHERE `serverID`='".$sID."'";
$result = mysql_query($query, $con) or die(mysql_error());
//Update Current Players
$query = "UPDATE `Servers` SET `serverPlayers`=serverPlayers + 1 WHERE `serverID`='".$sID."'";
$result = mysql_query($query, $con) or die(mysql_error());
//TO-DO Here Wait 5 minutes and perform another query
}
Upvotes: 0
Views: 149
Reputation: 9782
Use setTimeout()
in javascript
// Wait for 3 Seconds then execute
setTimeout(function(){
// your action
}, 3000);
// In Every 3 Second Execute
setInterval(function(){
// your action
}, 3000);
Upvotes: 1