期待资源,布尔给出问题

时间:2014-08-30 19:45:51

标签: php mysql

编辑:对于那些认为这是重复的人,它不是,因为它是没有返回任何内容的查询,而不是返回的结果。 $ id === FALSE方法不起作用!!

我遇到了代码问题(如下)。变量$ fn和$ ln是对数据库的查询,当被回显时,显示正确的输出,但是,在第二个mysql_result(mysql_query())中它会产生错误通知我:

  

警告:mysql_result()要求参数1为resource,boolean   给定的   /Applications/XAMPP/xamppfiles/htdocs/falsenine/createTeam.php上线   47

注意:查询正在尝试从正确命名的数据库,表,列名等中进行选择。

代码:

$clubID = 1;

$gkNum = rand(2,3);
$lbNum = rand(1,2);
$rbNum = rand(1,2);
$cbNum = rand(3,5);
$lmNum = rand(1,2);
$rmNum = rand(1,2);
$cmNum = rand(3,5);
$stNum = rand(2,4);

$teamNum = $gkNum + $lbNum + $rbNum + $cbNum + $lmNum + $rmNum + $cmNum + $stNum;

    while ($gkNum > 0) {
        $role = rand(1,2);
        $age = rand(16, 29);
        $nationality = rand(1, 27);         
        $nation = mysql_result(mysql_query("SELECT `nation` FROM nations WHERE `nationid` = " . $nationality), 0);
        $firstName = rand(1,20);
        $firstName = $firstName + (($nationality * 20) - 20);
        $fn = mysql_result(mysql_query("SELECT `fn` FROM firstName WHERE `nationality` = " . $nationality . " AND `fnid` = " . $firstName), 0);
        $lastName = rand(1,20);
        $lastName = $lastName + (($nationality * 20) - 20);
        $ln = mysql_result(mysql_query("SELECT `ln` FROM lastName WHERE `nationality` = " . $nationality . " AND `lnid` = " . $lastName), 0);
        mysql_query("INSERT INTO players (position, role, age, nationality, firstName, lastName, clubID) VALUES ('gk', $role, $age, '$nation', '$fn', '$ln', $clubID)");
        $id = mysql_result(mysql_query("SELECT `player_id` FROM players WHERE `firstName` = " . $fn . " AND `lastName` = " . $ln . " AND `clubID` = " . $clubID), 0);
        mysql_query("INSERT INTO playerStats (playerid) VALUES ($id)");
        $gkNum--;
    }

非常感谢任何帮助,如果需要更多详细信息,请告诉我们!谢谢!

0 个答案:

没有答案