1

I have a weird problem. Every time i execute this query in php i get the output "Challenge" even if the query is empty (should get "emptyq" if empty) when i test it in phpmyadmin everything is great and query is empty when it should be. I also tried to echo $detectChallengeRes[0][1] and got nothing. I cant find the problem, any help is very appreciated. The script is suppose to look in the database and check if there is any challenges associated with the current userID, its basically a script that checks if a user has been challenged by another user, the gameID on the current page is the same as the one in the database and that the user hasnt completed the challenge already ($yourscore==0).

$detectChallengeRes = query("SELECT * FROM `AMCMS_challenges` WHERE `gameid`=$gameid AND `winner`=0 AND (`userkey1`=$user OR `userkey2`=$user);");
        if($detectChallengeRes[0][1]!=$user && $detectChallengeRes[0][2]==$user) {
            $yourscore = $detectChallengeRes[0][6]; //Check your score to see if you've already played
        } elseif ($detectChallengeRes[0][2]!=$user && $detectChallengeRes[0][1]==$user) {
            $yourscore = $detectChallengeRes[0][5]; //Check your score to see if you've already played  
        } 
if ($detectChallengeRes!=NULL && $yourscore==0) {
echo 'Challenge';   
} else {
echo 'emptyq';
}

Table structure:

CREATE TABLE IF NOT EXISTS `AMCMS_challenges` (
  `primkey` int(11) NOT NULL auto_increment,
  `userkey1` int(11) NOT NULL,
  `userkey2` int(11) NOT NULL,
  `gameid` int(11) NOT NULL,
  `winner` int(11) NOT NULL,
  `score1` int(11) NOT NULL,
  `score2` int(11) NOT NULL,
  PRIMARY KEY  (`primkey`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
2
  • Why you don't use associate arrays? Can you provide DB table structure?
    – antyrat
    Jul 29, 2010 at 9:41
  • what does your query() function return? with sizeof() you can see the size of an array and mysql_num_rows() will get the number of rows from the result.
    – Ties
    Jul 29, 2010 at 9:47

3 Answers 3

0

$detectChallengeRes will be boolean false or mysql result resource. It will not be ever null.

0

This might not solve your question but It looks like it is showing an previous data. Put this before your script

unset($detectChallengeRes);
1
  • unset($detectChallengeRes); Didnt help :( still shows results. I am sure its something dumb and i just cant figure it out :( I hate being new to mysql and php :D Thanks for the help btw
    – Krasi
    Jul 29, 2010 at 9:52
0

Test for the number of rows returned by your query before trying to process it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.