Jump to content

Archived

This topic is now archived and is closed to further replies.

Dane

Error

Recommended Posts

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:

[code]
<?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);

?>
[/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 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: [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.

Thanks

Dane


Share this post


Link to post
Share on other sites
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());

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Yeah. You should always chercked to see if your query actually worked before trying to use the results from it.

Share this post


Link to post
Share on other sites
Lol, Yep.

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.