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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.