otuatail Posted April 28, 2010 Share Posted April 28, 2010 Hi I am trying to update a table The query works for retreving a single row but when in a loop it fails. This works $sql = "SELECT * FROM EventLog where EventID = 3069"; $query = mysql_query($sql) or die(mysql_error()); $rs = mysql_fetch_array($query); echo $rs['EventID']; This dosnt ?php session_start(); include ("functions.php"); connectDB(1); $sql = "SELECT * FROM EventLog where EventID > 3069"; $query = mysql_query($sql) or die(mysql_error()); //$rs = mysql_fetch_array($query); //echo $rs['EventID']; while ($row = mysql_fetch_array($query)) // Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource { $event = $row['EventID']; $date = date('Y-m-d H:i:s' , $row['Stamp']); // ****** // $sql2 = "UPDATE EventLog SET Date = '$date' WHERE EventID = $event"; $query = mysql_query ($sql2); } ?> Can't see the problem Link to comment https://forums.phpfreaks.com/topic/200052-while-fetch_array-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 28, 2010 Share Posted April 28, 2010 You are reusing the $query variable inside of the loop. It no longer has the result resource from the first query when the while(){} condition is evaluated the second time. Be careful when using variables. Link to comment https://forums.phpfreaks.com/topic/200052-while-fetch_array-error/#findComment-1049972 Share on other sites More sharing options...
otuatail Posted April 28, 2010 Author Share Posted April 28, 2010 Can't see the problem. I have used this before $sql = "SELECT * FROM EventLog where EventID > 3069"; $query = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($query)) // Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource { } Link to comment https://forums.phpfreaks.com/topic/200052-while-fetch_array-error/#findComment-1049979 Share on other sites More sharing options...
otuatail Posted April 28, 2010 Author Share Posted April 28, 2010 Sorry going blind $query2 = mysql_query ($sql2); // ERROR Link to comment https://forums.phpfreaks.com/topic/200052-while-fetch_array-error/#findComment-1049980 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.