...

View Full Version : Row doesn't update.



Krentenbol
12-26-2011, 11:18 PM
Does someone know why the rows checks and down doesn't update:




<?php
include('inc/config.php');
$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'] );
}else{
mysql_query("UPDATE status SET online=1,checks=checks+1 WHERE id=" . $row['id'] );
mysql_query("UPDATE lastchecktime SET ". $time ."" ." WHERE id=". $row['id'] );
}
fclose($sock);
}
}
?>

Keleth
12-27-2011, 12: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.

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

guelphdad
12-28-2011, 02:28 AM
Krentenbol

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.

Thanks

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum