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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Row doesn't update.

    Does someone know why the rows checks and down doesn't update:

    Code:
    <?php
    include('inc/config.php');
    $id = $_GET['id'];
    $result = mysql_query("SELECT * FROM status WHERE id = '$id'",$db) or die (mysql_error());
    while ($row = mysql_fetch_assoc($result))
    $lastcheck = $row['lastchecktime'];
    $time = time();
    if ($time - $lastcheck > 5*60) {
    while ($myrow = mysql_fetch_assoc($result))
    {
    if (! $sock = @fsockopen($row['ip'], $row['port'], $num, $error, 5))
    {
    mysql_query("UPDATE status SET online=0,checks=checks+1,down=down+1"
    . " WHERE id=" . $row['id'] );
    mysql_query("UPDATE lastchecktime SET ". $time ."". " WHERE id=" . $row['id'] );
    }else{
    mysql_query("UPDATE status SET online=1,checks=checks+1 WHERE id=" . $row['id'] );
    mysql_query("UPDATE lastchecktime SET ". $time ."" ." WHERE id=". $row['id'] );
    }
    fclose($sock);
    }
    }
    ?>
    Last edited by Fou-Lu; 12-28-2011 at 03:05 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,537
    Thanks
    45
    Thanked 259 Times in 256 Posts
    You've already pulled the query data with your first while loop, so $result's internal pointer is at the end. Use mysql_data_seek to reset the pointer so you can loop through the rows again, if you want to do something like this.

    Not sure why you need a while loop at all when you're checking for a single row. It could just as well be an if statement if you only want to assign $lastcheck if the result is valid. A while loop is not the right check to use there. Plus, by doing that, you've already assigned the value to $row, so why reassign it to $myrow? Again, seems pointless. You've already verified the data exists and put it into a variable.

    I also note you're closing $sock even if its not opened.

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I rewrote it, with your points in my mind. It's working now, thanks.

  • #4
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Krentenbol

    please don't post a thread to a public forum asking for help and then delete the item once it has been solved (as you have done in this thread).

    doing so defeats the purpose of a forum, which in getting you help for your problem, also may help others solve a similar problem they are having.

    Thanks

  • #5
    Regular Coder
    Join Date
    Sep 2011
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    K, I will repost it, if I can still find it, I'll post the new code anyways.


  •  

    Posting Permissions

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