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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post

    Update every user with loop?

    PHP Code:
    <?php
    require "config.php";
    $query mysql_query("SELECT plan, timeleft FROM userinfo");
    while (
    $qrow mysql_fetch_array($query)) {
    $plan $qrow['plan'];
    $timeleft $qrow['timeleft'];
    if (
    $plan != 0) {
        if (
    $timeleft != || $plan != 123456789) {
        
    mysql_query("UPDATE userinfo SET timeleft = timeleft - 1");
        }
    }
    }


    ?>
    I am trying to do this but instead of minus 1 it is minus 3 on all colums and sometimes -45 and it's doing it to every user even if plan is 0 and time is 0
    This is suppose to be an auto cron

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    No. There is absolutely no reason to update every record in a while loop.
    PHP Code:
    mysql_query("UPDATE userinfo SET timeleft = timeleft - 1 WHERE timeleft > 0 AND plan NOT IN (0, 123456789)"); 
    Just because you have controlled a variable in PHP doesn't mean that it will be controlled in SQL. You must provide it with a criteria or it is ALL records.

  • Users who have thanked Fou-Lu for this post:

    Vernk (10-06-2012)

  • #3
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post
    Hey thanks,
    It looks like it worked. I knew there was a way to do it in SQL just didn't know how


  •  

    Posting Permissions

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