Jump to content

Updating the current record


cliftonbazaar

Recommended Posts

The following code loops through all the data in a particular table and edits any record that is behind in time, then updates it.

So how do I get it to update just the record that I am working on?  I realise the quick answer is to have '$sql' use  a WHERE statement to find the record again but wouldn't this include going through the whole database again to find the record slowing the whole process down?

  WHILE($match = mysql_fetch_array($matches)) {  //Go through all the matches
    if(time()>$match['updateTime']) {  //This means we need do update it

          //DO x y and z

  $d=$match['updateTime']+60;  //Update the timer (add another minute))

  //Update the database
  $sql = "UPDATE matches SET updateTime='{$updatedTime}'";		
  if(!mysql_query($sql,$sqldb)) die('Error: ' . mysql_error());  //Update the record, if there is an error then show it
}
  }

Link to comment
https://forums.phpfreaks.com/topic/187625-updating-the-current-record/
Share on other sites

Using WHERE is the way forward. I assume there is a field used as an id so you simply use WHERE id=$match['id']. The record set returned by your original mysql_query is just a block of data so there is no way to update the actual database through that record set.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.