joecooper Posted September 8, 2008 Share Posted September 8, 2008 Hi, I have this code for a hit counter: $query = mysql_query("SELECT * FROM games WHERE id=$id"); $row = mysql_fetch_assoc($query); $updateplays=$row['plays'] + 1; $query = "UPDATE games SET plays = '$updateplays' WHERE id = '$id'"; mysql_query($query) or die('Error, query failed'); it works well, adds a number everytime the page is viewed. is there a way to make it wait 10 seconds and then add's 1 to the counter? the reason is so it will count only people spending time on the page. Link to comment https://forums.phpfreaks.com/topic/123258-slightly-different-hit-counter/ Share on other sites More sharing options...
JonnoTheDev Posted September 8, 2008 Share Posted September 8, 2008 You would need ajax to do that in the background. Also you should use SQL syntax to do the increment rather than application logic: $query = "UPDATE games SET plays = plays+1 WHERE id = '$id'"; Link to comment https://forums.phpfreaks.com/topic/123258-slightly-different-hit-counter/#findComment-636535 Share on other sites More sharing options...
joecooper Posted September 8, 2008 Author Share Posted September 8, 2008 understood, and thanks. Link to comment https://forums.phpfreaks.com/topic/123258-slightly-different-hit-counter/#findComment-636539 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.