Results 1 to 4 of 4

Thread: Database Changes At Scheduled Times

  1. #1
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Database Changes At Scheduled Times

    Well, I am making a script that will update all users ranks every 7 days. What I came up with was to just include this page in another page that will be accessed all the time:
    PHP Code:
    <?php

    $get 
    mysql_query("SELECT id, level, last_pro, signup FROM `users` WHERE status = 'active'") or die ("Error Getting User Data! \n<br />\n" .mysql_error());

    while (
    $u mysql_fetch_array($get)) {
        if ( !
    $last_pro && $signup >= (time()-60*60*24*7) ) { $level $u['level'] + 1$last_pro date('n/j/y [g:i A]'); }
        else if ( 
    $last_pro >= (time()-60*60*24*7) ) {  $level $u['level'] + 1$last_pro date('n/j/y [g:i A]'); }
        
    $update mysql_query("UPDATE `members` SET level = '$level', last_pro = '$last_pro' WHERE id = '$id'") or die ("Error Updating Levels! \n<br />\n" .mysql_error());
    }

    ?>
    I am not 100% sure that this will work. Will that script add 1 to a user level 7 days after their previous promotion? Also is including this in a commonly accessed page the best way to do this? Thanks in advance
    Thanks DD, you saved me countless times

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Try:
    Code:
    UPDATE users SET level = level + 1, last_pro = NOW() WHERE status = active AND DATE_SUB(NOW(), INTERVAL 7 DAY) > last_pro;
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok, that helps me out a lot and cuts down the code significantly . Can I use this code to also delete users after 8 days of inactivity by changing it to this:
    Code:
    DELETE FROM `users` WHERE status = active AND DATE_SUB(NOW(), INTERVAL 8 DAY) > last_login;
    I ask just because it will take a while to know for sure if it works (the span of time in the script). Let me know, thanks.
    Thanks DD, you saved me countless times

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yes.&#32;
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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