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 7 of 7
  1. #1
    New Coder
    Join Date
    Sep 2007
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question updating multiple rows

    I have a user table in which each record has an id and a date field (among otheres)
    the id is int and the date field is date formatted 0000-00-00

    I want a query to run any time this page is viewed (this way no form is needed) that it would update the date field in every record when compared to the current date.

    PHP Code:
        $now date ('Y-m-d');
            
        
            
    $query "SELECT * FROM `t1m_users` WHERE `active` ='1' ";
            
    $result mysql_query($query) or die(mysql_error());
                
                
    $i 0;
            while    
    $row mysql_fetch_array($result));{
            
    $id $row['id'];
            
    $expired $row['join_expd'];
            
            ++
    $i;
            } 
    I know I need to loop and check each users 'join_expd' field and compare it to $now then if it is greater (meaning now = 2008-07-15 and join_expd = 2008-07-14 ) I want to set the active fields to '0'.

    this will set all users accounts who have expired to inactive. I dont want to delete them.

    thanks in advance for the help


    best regards,

    MM

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Check the syntax of while loop from http://in.php.net/while
    Have you got any error from your current code?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    Can't he just use one query with no limit instead of multiple queries in a loop?
    PHP Code:
    $sql "UPDATE `tlm_users` SET `active`='0' WHERE `join_expd` < CURDATE()";
    $query mysql_query($sql); 
    Untested but I think it would work.

  • Users who have thanked fl00d for this post:

    ido3dfx (07-14-2008)

  • #4
    New Coder
    Join Date
    Sep 2007
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by fl00d View Post
    Can't he just use one query with no limit instead of multiple queries in a loop?
    PHP Code:
    $sql "UPDATE `tlm_users` SET `active`='0' WHERE `join_expd` < CURDATE()";
    $query mysql_query($sql); 
    Untested but I think it would work.
    how would it know what record/row to update ? with that query I am prettty sure it would only do the last record with the expired date.

  • #5
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    no... it would change any rows meeting the specified conditions

  • Users who have thanked ohgod for this post:

    ido3dfx (07-14-2008)

  • #6
    New Coder
    Join Date
    Sep 2007
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ohgod View Post
    no... it would change any rows meeting the specified conditions
    you know....BY GEORGE I think you've got it!!


    I'll give it a run.

  • #7
    New Coder
    Join Date
    Sep 2007
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    You Da Man !!!


  •  

    Posting Permissions

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