cliftonbazaar Posted January 7, 2010 Share Posted January 7, 2010 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 } } Quote Link to comment https://forums.phpfreaks.com/topic/187625-updating-the-current-record/ Share on other sites More sharing options...
cags Posted January 8, 2010 Share Posted January 8, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/187625-updating-the-current-record/#findComment-990818 Share on other sites More sharing options...
cliftonbazaar Posted January 8, 2010 Author Share Posted January 8, 2010 Thanks for the reply Quote Link to comment https://forums.phpfreaks.com/topic/187625-updating-the-current-record/#findComment-991303 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.