View Full Version : Row doesn't update.

12-27-2011, 12:18 AM
Does someone know why the rows checks and down doesn't update:

$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'] );
mysql_query("UPDATE status SET online=1,checks=checks+1 WHERE id=" . $row['id'] );
mysql_query("UPDATE lastchecktime SET ". $time ."" ." WHERE id=". $row['id'] );

12-27-2011, 01:35 AM
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.

12-27-2011, 10:54 AM
I rewrote it, with your points in my mind. It's working now, thanks:).

12-28-2011, 03:28 AM

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.


12-28-2011, 01:05 PM
K, I will repost it, if I can still find it, I'll post the new code anyways.