...

View Full Version : Help with simple mysql query and php



Anthony2oo4
11-25-2006, 01:49 PM
Hey there,

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

1148533200

I used this site for it:
http://www.plus2net.com/php_tutorial/php_time_stamp.php

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.

wallport10
11-25-2006, 05: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();

GJay
11-25-2006, 06:36 PM
echo strtotime('6 months ago');
//or
echo strtotime('-6 months');

http://php.net/strtotime

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

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

thanks.

GJay
11-25-2006, 09: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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum