0

当我阅读有关此功能的 php 手册时,我认为我正在正确执行它。不幸的是,我收到了这个错误:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given on line 94

使用此代码:

$upSQL = "SELECT * FROM rated_teams WHERE server='$server' AND name='$teamname' AND master='2' ORDER BY id ASC;";
$upSQL .="SELECT name, rating FROM rated_teams WHERE server='$server' AND master='1'";
//echo $upSQL. "<br />";
$upresult=mysqli_multi_query($con, $upSQL);
$i=1;
$j=1;
$myrating=0;
while($row = mysqli_fetch_array($upresult)) { //LINE 94
    if ($row['win'] == 1 && $i <= 3) {      
            echo $i++ . "first 3 wins <br />";
            $myrating+=10;
            $j++;

        } else {
            if ($row['name'] == $opposer && $row['master'] == 1) {
                echo $opposer . " " . $row['rating'];
                echo $j++. " j<br />";
            }

            }
}
echo $myrating;

所以,直接的问题是:为什么这段代码不正确?

4

1 回答 1

1

mysqli_multi_query方法返回一个布尔值,而该方法mysqli_fetch_array应该被传递 a mysqli_result,正如错误告诉你的那样。您需要改用mysqli_store_result此处所示的方法:

http://php.net/manual/en/mysqli.multi-query.php

使用此方法,您可以遍历结果,如下所示:

if (mysqli_multi_query($con, $upSQL)) {
do {
    if ($result = mysqli_store_result($con)) {
        while ($row = mysqli_fetch_row($result)) {
            $currentresult = $row[0];
        }
        mysqli_free_result($result);
    }
} while (mysqli_next_result($con));
}

do-while 确保您的第一个结果在转到其他结果之前就在那里,并获得该结果,然后在循环的 while 段中为您提供下一个结果。希望这会有所帮助。

于 2013-08-05T01:30:23.723 回答