Jump to content

Recommended Posts

Hello again nice people :D!

 

Ok so I want to make it so that when you query a page, it checks the CURRENT_TIMESTAMP to a row, and then if that rows timestamp is at least 10 minutes behind..well yeah, do some code. However the hard part comes when I want to know how many 10 minutes behind it is, so lets say its 40 minutes behind the current timestamp, then I want to add 40 points. So anyone got any ideas? Sorry for all these questions, I'm new to PHP/SQL programming :)

 

 

Link to comment
https://forums.phpfreaks.com/topic/148517-phpmysql-help/
Share on other sites

well..

 

lets break that down;

 

1) Your script will ONLY be affecting the rows which are older than 10 minutes, if I'm right continue onto step 2..

 

2) in order to select rows older than 10 minutes, what would be a good query,

 

-->a) (IF UNIX TIMESTAMP) "SELECT * FROM `table` WHERE `theTimestamp` < '".(time() - (60 * 10))."'"

 

-->b) (IF DATETIME FIELDTYPE) "SELECT * FROM `table` WHERE `theTimestamp` < DATE_SUB(NOW(),INTERVAL 10 MINUTE b)

 

3) grab the results

 

$qry = mysql_query($sql);
while ($r = mysql_fetch_assoc($qry)) {
  $results[] = $r;
}
// see step 4

 

4) do the math on each result, possibly in a foreach for the array $results, gather the ids and the time difference, then do the changes in another query

Link to comment
https://forums.phpfreaks.com/topic/148517-phpmysql-help/#findComment-779893
Share on other sites

mysql_query('UPDATE `users` SET actionpoints = actionpoints + 10 * (MINUTE(TIMEDIFF(CURRENT_TIMESTAMP,lastactionpoints)) DIV 10) WHERE username = "'.$row['username'].'"');

 

Doesn't work..any ideas? :D

 

I kind of want it more like..every 10 minutes on the 10 minute point, you get 10 actionpoints. So this wouldn't do that really :(

Link to comment
https://forums.phpfreaks.com/topic/148517-phpmysql-help/#findComment-779993
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.