dtzd65908 2013-08-05 01:20
浏览 39
已采纳

mysql多查询功能不正确

As I read the php manual on this function, I though that I was executing it correctly. Unfortunately I'm getting this error:

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

with this code:

$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;

So, the direct question is: Why is this code incorrect?

  • 写回答

1条回答 默认 最新

  • doushui3061 2013-08-05 01:30
    关注

    The mysqli_multi_query method returns a boolean, while the method mysqli_fetch_array is supposed to be passed a mysqli_result, as the error tells you. You need to instead use the mysqli_store_result method as seen here:

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

    Using this method, you can loop through the results, as so:

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

    The do-while makes sure that your first result is there before going to the others, and gets that result, and then gives you the next results in the while segment of the loop. Hope this was helpful.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度