0

I am using php and mysql and have no java knowledge. After searching I have found many countdown timers for javascript but they are client-side. I am looking for something that is server-side based. I have a table in mysql with a column called TimeRemaining. That column stores future time records. I need to load the record with the least time remaining so that when it hits zero that record is removed from the table and a new countdown timer begins with the next record with the least amount of time remaining. Also, if a new record is inserted with less time remaining than the previous record with the least time remaining, the timer needs to be updated with the new record. Is this possible and/or recommended through using triggers to update an event in mysql or can I create a countdown timer in php.

Thank you all for any help. Edit: I mentioned Java/Javasript because I would like to avoid it as I have no knowledge of it and through research I have seen most posts using java. For a better understanding of what I want to do, multiple users are banned from creating posts in a forum for 7 days. I have a table in mysql that stores that ban and the time it expires. I need to automatically remove that record from the table when the 7 days expires. The user should have no control over this timer. I do not need to display the time remaining on a webpage. I need this to happen in the background with no user intervention. Is that clearer ?

4
  • 1
    If you are storing the future time, you don't need a countdown timer at all. Do you mean you want to show how long until that timer is up on your page? You can't do that in PHP, you need to use javascript. Commented Apr 30, 2012 at 17:14
  • 4
    "I am using php and mysql and have no java knowledge." What do you want to do with Java? Commented Apr 30, 2012 at 17:14
  • 2
    Something is seriously wrong with your architecture. Looks like you should save time for 'deleting' record in database and then run PHP script with cron to delete records when needed. Commented Apr 30, 2012 at 17:16
  • I suggest you learn enough javascript to use it here. Commented Apr 30, 2012 at 17:38

2 Answers 2

3

You want to do this client-side. On pageload, you can pull the countdown time from the SQL table and client-side countdown THAT time. Once the time is complete, you can do a call (synchronous or AJAX) to the server (PHP) again to remove that record.

Sign up to request clarification or add additional context in comments.

3 Comments

Lion, I want to avoid Java/Javascript if possible as I have no knowledge of it. Example, someone is banned from creating posts in a forum for 7 days. I have a table in mysql that stores that end time. I need to automatically remove that record from the table when the 7 days expires. Is that clearer ?
Ray, for this case you'd want to either have a job running every 24 hours to unban people, or you could also have a ban end date column in your users table and check against that column when a user logs in -- if current date exceeds ban end date, then the user is good to go. If you definitely want to have a "countdown" and remove a row, you will not want to use PHP.
Thanks dweiss, I definitely do not want to have the table ONLY updated if the user logs in. I want the record to be removed at the exact time regardless if the user is logged in or not. I think I may create an event in mysql to remove the record and have php alter the event when/if needed.
0

Considering you said you have little knowledge of javascript I would make a little iframe in your page that refresh automatically and show the last time checked accordingly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.