Problem with query not understood. [Solved]

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dwessell
Forum Commoner
Posts: 62
Joined: Fri Dec 23, 2005 2:30 pm

Problem with query not understood. [Solved]

Post 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);

}
Last edited by dwessell on Sun Jan 01, 2006 3:41 pm, edited 1 time in total.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Re: Problem with query not understood.

Post 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'
dwessell
Forum Commoner
Posts: 62
Joined: Fri Dec 23, 2005 2:30 pm

Re: Problem with query not understood.

Post 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..
dwessell
Forum Commoner
Posts: 62
Joined: Fri Dec 23, 2005 2:30 pm

Post 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
dwessell
Forum Commoner
Posts: 62
Joined: Fri Dec 23, 2005 2:30 pm

Post by dwessell »

PEBKAC error..

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

Sometimes I amaze myself :-)
Post Reply