Page 1 of 1

Problem with query not understood. [Solved]

Posted: Sun Jan 01, 2006 8:34 am
by dwessell
Hey all.. I'm having a bit of a time understanding where I have written the query below incorrectly..

'Status' is either a 1 or a 2 or a 0.

I recieve errors when it's a 0, but not when it's a 1. But the UPDATE query seems to run anyway, even with the error message displaying..

Secondly, even when there isn't anything in the database for the query to run on (Nothing with the correct TimeStamp and correct status) The echo is being processed so the while loop is running..

Any thoughts would be appreciated.

Thanks
David


Code: Select all

$query  = "SELECT * FROM `Game Information` WHERE `TimeStamp` <= $timeStamp AND `Status` = 0"; 
$result = mysql_query($query);
while( $row = mysql_fetch_array($result, MYSQL_NUM) ){

echo "We are here";
		
$gameQuery = "UPDATE `Game Information` SET `Status` = 1 WHERE `Game Number` = $row[0]";
$result = mysql_query($gameQuery);

}

Re: Problem with query not understood.

Posted: Sun Jan 01, 2006 8:44 am
by timvw
What is the datatype of Status?

Btw, if i get it right, the following query should do what you are trying to do in a loop:

Code: Select all

UPDATE `Game Information` 
SET `Status`='1'
WHERE `TimeStamp` <= '$timeStamp' AND `Status`='0'

Re: Problem with query not understood.

Posted: Sun Jan 01, 2006 8:49 am
by dwessell
timvw wrote:What is the datatype of Status?

Btw, if i get it right, the following query should do what you are trying to do in a loop:

Code: Select all

UPDATE `Game Information` 
SET `Status`='1'
WHERE `TimeStamp` <= '$timeStamp' AND `Status`='0'

Hey Tim... Status is an int(14)..
Thanks for that bit of code.. I structured it as I did,becuase I'm preforming a few other operations (sending mail, etc) and it made sense in my little brain to traverse the array updating and preforming misc operations as we go.. But I hadn't thought of structuring the query as you did.. Thanks..

Posted: Sun Jan 01, 2006 10:28 am
by dwessell
Update: This is the echo, and the error message given.

Code: Select all

Resource id #342
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/background/15min.php on line 27
Thanks
David

Posted: Sun Jan 01, 2006 3:43 pm
by dwessell
PEBKAC error..

I had resused the $result variable before it had gone out of scope..

Sometimes I amaze myself :-)