Jump to content


Photo

Error


  • Please log in to reply
4 replies to this topic

#1 Dane

Dane
  • Members
  • PipPipPip
  • Advanced Member
  • 102 posts
  • LocationGrimsby

Posted 06 June 2006 - 09:47 AM

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.9

The Script is:

<?php

include_once('../Included_Files/Database_Connect.php'); // This Connects To The MySQL Database

ConnectDatabase();

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 Function

UpdateDailyCondition($db);

?>

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 26


Player Has Been Updated By 0.12 From To 0
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\dir\condition_update.php on line 67

Line 26 being:
$myrow = mysql_fetch_array($result);
Line 67 being:
while ($myrow = mysql_fetch_array($result)); // This Gets The Next Player In The Database

Any help would be great.

Thanks

Dane



Nothing....

#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 06 June 2006 - 09:54 AM

while ($myrow = mysql_fetch_array($result)); // This Gets The Next

Where 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());
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#3 Dane

Dane
  • Members
  • PipPipPip
  • Advanced Member
  • 102 posts
  • LocationGrimsby

Posted 06 June 2006 - 10:09 AM

I get the error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\dir\condition_update.php on line 26


Player 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 1

Fixed 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 working

thanks a lot

Dane
Nothing....

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 06 June 2006 - 10:15 AM

Yeah. You should always chercked to see if your query actually worked before trying to use the results from it.

#5 Dane

Dane
  • Members
  • PipPipPip
  • Advanced Member
  • 102 posts
  • LocationGrimsby

Posted 06 June 2006 - 12:36 PM

Lol, Yep.

I always make mistakes in my coding however im always sucessfull making it right. Most times its just one "little" mistake.
Nothing....




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users