Welcome to the Browser-Base Game Zone forums!
INSERT INTO logins(id_user,time_login) VALUES ('$user_id',NOW())
SELECT user_id FROM users WHERE user_id NOT IN (SELECT id_user FROM logins WHERE DATEDIFF(CURDATE(), time_login) < 30)
why do you store every login? do you need to know times for every user for last week?
select * from users where lastclick < NOW() - interval 30 day
Ignoring the other reasons to have a seperate login table, to find out which users are dormant why not just store UNIX_TIMESTAMP() into whatever main users table every time they login (or are active?) and then do a search on that (SELECT `id`,`username` FROM `users` WHERE `time_login/time_activity` < UNIX_TIMESTAMP()-(86400*30). I would have thought that's the best way to find dormant users.
select id, username from users where last_activity_at >= date_sub(now(), interval 30 day);