我有一个奇怪的问题。每次我在 php 中执行这个查询时,即使查询为空(如果为空,应该得到“emptyq”),当我在 phpmyadmin 中测试它时,我得到输出“Challenge”,一切都很好,查询在它应该是空的时候是空的。我还尝试回显 $detectChallengeRes[0][1]
但一无所获。我找不到问题,非常感谢任何帮助。
该脚本假设在数据库中查看并检查是否有任何与当前用户 ID 相关的挑战,它基本上是一个检查用户是否已被另一个用户挑战的脚本,当前页面上的游戏 ID 与该用户相同在数据库中并且用户尚未完成挑战 ($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';
}
表结构:
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 ;
最佳答案
$detectChallengeRes 将为 bool 值 false 或 mysql 结果资源。它永远不会为空。
关于php 脚本行为怪异,即使记录不存在也会显示记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3361102/