Cyto Posted October 11, 2010 Share Posted October 11, 2010 Hi, I want to update a row when 30sec are passed on a page. If not nothing happens(not updating row). Example: You go to example.php>> 30sec pass, update row>> 30sec not over, no update. it does not necessarily have to be second it can be minutes or hours. Who can help me? Hope its clear enough, Thanks. Quote Link to comment Share on other sites More sharing options...
btherl Posted October 12, 2010 Share Posted October 12, 2010 Do you want the update to occur if the user is still viewing the page after 30 seconds? In that case I would use ajax with a timer. If you want it to act more like a timeout, where something occurs unless the user does something within a time limit, then you could store a timestamp in the database. When they take the required action you check the timestamp and see if it's more than 30 seconds old. In this case the action won't occur exactly after 30 seconds, but maybe that doesn't matter. It depends on the reason for the 30 seconds. Quote Link to comment Share on other sites More sharing options...
Cyto Posted October 12, 2010 Author Share Posted October 12, 2010 Yes, If the user is viewing the page within 30 sec or min, hours update row if not, do nothing. Is this possible with php only? cus dont know ajax. Quote Link to comment Share on other sites More sharing options...
btherl Posted October 12, 2010 Share Posted October 12, 2010 This might be the time to learn ajax It's actually very simple if you use jquery. It can be as simple as this: $.get('mark_user_as_timed_out.php'); You would want to have that executed after a 30 second delay, using javascript setTimeout(), such as at http://www.htmlite.com/JS018.php . What will happen is the user's browser will run that php script, but their page won't be updated (unless you want it to be). Quote Link to comment Share on other sites More sharing options...
atrum Posted October 12, 2010 Share Posted October 12, 2010 My advise is look up jquery ajax.post http://api.jquery.com/jQuery.post/ and php-json. http://www.php.net/manual/en/book.json.php Made my life easy for those types of issues. Quote Link to comment Share on other sites More sharing options...
Cyto Posted October 12, 2010 Author Share Posted October 12, 2010 This might be the time to learn ajax It's actually very simple if you use jquery. It can be as simple as this: $.get('mark_user_as_timed_out.php'); You would want to have that executed after a 30 second delay, using javascript setTimeout(), such as at http://www.htmlite.com/JS018.php . What will happen is the user's browser will run that php script, but their page won't be updated (unless you want it to be). Would you mind explaining it further, getting confused $.get('mark_user_as_timed_out.php'); Is jQuery i know that its like including a php file. But the JS part is where i got stuck. How am i going to set a update row with JS on mark_user_as_timed_out.php? thanks for your comments much appreciated. Quote Link to comment Share on other sites More sharing options...
btherl Posted October 12, 2010 Share Posted October 12, 2010 What you would do is create a php script called "mark_user_as_timed_out.php". That script is php, so it can do anything you want, including updating the database, which you couldn't do directly from JS. If you have the user's information in a session then you can use that in mark_user_as_timed_out.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.