New to this forum and php so please go easy on me.
I have a php script that is dealing with data from multiple mysql tables in a database. I have all of the other queries working fine, but for some reason this one throws an error whenever the conditions are true to reach the mysql_fetch_array() command. I've been trying to find how this query differs from all the others, but have not had any success.
Does anyone see anything in the following segment of code that could lead to the following error?
$errorFlag = 0;
$result = 0;
$counter = 0;
$sql = "SELECT * FROM Data WHERE Last_Update < DATE_ADD(NOW(), interval -1 MINUTE)";
while (!$result && $errorFlag == 0) {
$result = mysql_query($sql);
$counter = $counter + 1;
if ($counter > 30) {
$errorFlag = 1;
}
}
if ($errorFlag == 1) {
echo "#E01,".$counter.",".mysql_errno().":".mysql_error()."!";
}
if ($errorFlag == 0 && mysql_num_rows($result) > 0) {
while(errorFlag == 0 && $row = mysql_fetch_array($result)) {
if ($row['Last_Update_Alarm'] == 0) {
$sql = "UPDATE $tbl_name SET Last_Update_Alarm='1', Status_Time='0' WHERE Machine_ID='$row[Machine_ID]'";
$counter = 0;
$result = 0;
while ($result == 0 && $errorFlag == 0) {
$result = mysql_query($sql);
$counter = $counter + 1;
if ($counter > 30) {
$errorFlag = 1;
}
}
}
}
}
This is the error code that I get:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:...\test.php on line 33
Line 33 corresponds to the line with fetch command. I checked the resource type and the number of rows after the query and both were as expected.
Thanks! Scott