Dane Posted June 6, 2006 Share Posted June 6, 2006 Hi Guys,I have an error on my PHP Script that is really starting to annoy me now and i cannot seem to fix it. Its probably something really silly and basic but its getting to me lol.I am using PHP Version 4.3.10 and MySQL 4.1.9The Script is:[code]<?phpinclude_once('../Included_Files/Database_Connect.php'); // This Connects To The MySQL DatabaseConnectDatabase();function UpdateDailyCondition($db){$strQuery = "SELECT id, non_technical_attibutes_stamina, condition from players where team <> 'R'";$result = mysql_query($strQuery,$db);$myrow = mysql_fetch_array($result);$id = $myrow['id'];$stamina = $myrow['non_technical_attibutes_stamina'];$condition = $myrow['condition'];if ($stamina >= 50){ $percentage = 0.02; }if ($stamina == 51 || $stamina <= 55){ $percentage = 0.03; }if ($stamina == 56 || $stamina <= 60){ $percentage = 0.04; }if ($stamina == 61 || $stamina <= 65){ $percentage = 0.05; }if ($stamina == 66 || $stamina <= 70){ $percentage = 0.06; }if ($stamina == 71 || $stamina <= 75){ $percentage = 0.07; }if ($stamina == 76 || $stamina <= 80){ $percentage = 0.08; }if ($stamina == 81 || $stamina <= 85){ $percentage = 0.09; }if ($stamina == 86 || $stamina <= 90){ $percentage = 0.10; }if ($stamina == 91 || $stamina <= 95){ $percentage = 0.11; }if ($stamina == 96 || $stamina <= 100){ $percentage = 0.12; }$newcondition = $condition*$percentage;$updatedcondition = round($condition+$newcondition);echo "Player $id Has Been Updated By $percentage From $condition To $updatedcondition";$strQuery = "UPDATE `players` SET condition = $updatedcondition WHERE id = $id";mysql_query($strQuery,$db);while ($myrow = mysql_fetch_array($result)); // This Gets The Next Player In The Database} // This Ends The Update FunctionUpdateDailyCondition($db);?>[/code]And the error is:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\dir\condition_update.php on line 26Player Has Been Updated By 0.12 From To 0Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\dir\condition_update.php on line 67Line 26 being: [code]$myrow = mysql_fetch_array($result);[/code]Line 67 being: [code]while ($myrow = mysql_fetch_array($result)); // This Gets The Next Player In The Database[/code]Any help would be great.ThanksDane Quote Link to comment https://forums.phpfreaks.com/topic/11311-error/ Share on other sites More sharing options...
samshel Posted June 6, 2006 Share Posted June 6, 2006 while ($myrow = mysql_fetch_array($result)); // This Gets The NextWhere is this while loop ending ??? you cannot use the ; at the end of while statement....Also try this...$strQuery = "UPDATE `players` SET condition = '$updatedcondition' WHERE id = $id";mysql_query($strQuery,$db) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/11311-error/#findComment-42350 Share on other sites More sharing options...
Dane Posted June 6, 2006 Author Share Posted June 6, 2006 I get the errorWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\dir\condition_update.php on line 26Player Has Been Updated By 0.12 From To 0You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1Fixed it.Im that stupid. In the 'player' database i didnt have the 'team' row.However samshel thanks for your help, the 'or die' bit help with knowing why it isnt workingthanks a lotDane Quote Link to comment https://forums.phpfreaks.com/topic/11311-error/#findComment-42352 Share on other sites More sharing options...
trq Posted June 6, 2006 Share Posted June 6, 2006 Yeah. You should always chercked to see if your query actually worked before trying to use the results from it. Quote Link to comment https://forums.phpfreaks.com/topic/11311-error/#findComment-42354 Share on other sites More sharing options...
Dane Posted June 6, 2006 Author Share Posted June 6, 2006 Lol, Yep.I always make mistakes in my coding however im always sucessfull making it right. Most times its just one "little" mistake. Quote Link to comment https://forums.phpfreaks.com/topic/11311-error/#findComment-42383 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.