Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post

    Help with simple mysql query and php

    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.

  • #2
    New Coder
    Join Date
    Aug 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?
    $month 
    mktime(000date("m")-6date("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!

    PHP Code:
    echo time(); 

  • #3
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    PHP Code:
    echo strtotime('6 months ago');
    //or
    echo strtotime('-6 months'); 
    http://php.net/strtotime

  • #4
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    Thank you both, seems to work fine.

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

    thanks.

  • #5
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    you don't need a loop, you can use the criteria of your first (select) query as the criteria for the second:
    Code:
    UPDATE cms_users SET <blah, your fields here> WHERE user_lastvisit < 1148533200

  • #6
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    Thanks, works a treat.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •