PHP How do you update individual records based on WHERE condition?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kadeous
    New Member
    • Jun 2010
    • 12

    PHP How do you update individual records based on WHERE condition?

    I am updating records using a cron job that works perfectly fine. The issue I have is that the script is updating all records using the information from the first row matching my WHERE condition.

    I'm using the following to query the database for data.

    The row I'm searching for information from is time in the database, and mtime is a row that holds max time for the test.
    Code:
    $query = "SELECT * FROM info WHERE class = 'Math'";
    $data = mysqli_query($db, $query);
    $row = mysqli_fetch_array($data);
    
    $time = 5;
    // Begin and IF statement to update the rows
    if ($row['time'] != $row['mtime']) {
        $updatetime = $query = "UPDATE info set time=time+$time, WHERE class = 'Math'";
    } // Close If
    So now what I want to be able to do is rather then having it only checking the mtime from the first row it pulls data from because each row has different mtime values. I would like to learn how to grab the first row check time vrs mtime update then move to the next record.

    Thanks for all help ahead of time!
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    #2
    I'm at work now, but when I get home I'll take a better look at this and see if I can help you out.

    Comment

    • kadeous
      New Member
      • Jun 2010
      • 12

      #3
      I did it using a while loop, worked perfectly! TY though!!

      Comment

      Working...