View Full Version : Help with simple mysql query and php

11-25-2006, 02:49 PM
Hey there,

First of all can anyone confirm that this timestamp is for 6 months ago?


I used this site for it:

If its not can someone show me how to use the mktime function to get a timestamp for 6 months ago.

Anyway my main problem is this. I have run a query on a databse of users as follows.

SELECT * FROM `cms_users` WHERE `user_lastvisit` < 1148533200

This should give me a list of all members who havnt visited us in the past 6 months. Now I want to suspend these users, and the query for this is:

UPDATE cms_users SET user_allow_pm=1, user_allowavatar=1, user_rank=21, susdel_reason='Non active member.', user_level=0, susdel_reason='Non active member.' WHERE user_id=9

(Dont know why susdel_reason is set twice, but i got the query off the CMS script itself)

How can I make a loop that will suspend each user with that query?

thanks for your time and help.

11-25-2006, 06:48 PM
$month = mktime(0, 0, 0, date("m")-6, date("d"), date("Y"));

It gave me this; 1148529600

And right now its; 1164476807

This is how you'll be able to do it! I tested it with this code which gives us the current time right now!

echo time();

11-25-2006, 07:36 PM
echo strtotime('6 months ago');
echo strtotime('-6 months');


11-25-2006, 09:38 PM
Thank you both, seems to work fine.

But what about the loop? Can anyone help me here ?


11-25-2006, 10:19 PM
you don't need a loop, you can use the criteria of your first (select) query as the criteria for the second:

UPDATE cms_users SET <blah, your fields here> WHERE user_lastvisit < 1148533200

12-02-2006, 11:18 PM
Thanks, works a treat.