thaidomizil Posted November 13, 2011 Share Posted November 13, 2011 Hi, i'm trying to create some detailed statistics about customer activity, i have entries in my mysql db when the customer has been active for the last time and want to create some statistics about that, basically a "online last 24 hours" but from specific countries. Now i've tried this: $time = date('Y-m-d H:i:s'); $time24 = date("Y-m-d H:i:s", time()-((60*60)*24)); $query = "SELECT COUNT(*) as Anzahl FROM customers WHERE country = 'de' AND time BETWEEN '$time' AND '$time24' "; to get the current date and select all customers that have been available from the current date minus 24 hours, what's my mistake here, as this doesn't seem to work! Thanks Link to comment https://forums.phpfreaks.com/topic/251068-online-in-last-24-hour/ Share on other sites More sharing options...
Pikachu2000 Posted November 13, 2011 Share Posted November 13, 2011 The lower value needs to come first in a BETWEEN comparison, but this would be better handled in the query anyhow. PHP's DATE function is pretty slow. time BETWEEN DATE_SUB( NOW(), INTERVAL 24 HOUR ) and NOW() Link to comment https://forums.phpfreaks.com/topic/251068-online-in-last-24-hour/#findComment-1287863 Share on other sites More sharing options...
thaidomizil Posted November 13, 2011 Author Share Posted November 13, 2011 Thank you Pikachu, i expected to have some logical error in there, your solution works great anyhow! Link to comment https://forums.phpfreaks.com/topic/251068-online-in-last-24-hour/#findComment-1287864 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.