警告:mysqli_fetch_array()期望参数1为mysqli_result,布尔值为

时间:2016-05-31 15:01:53

标签: php mysqli

如何修复mysqli_fetch_array()要求参数1为mysqli_result,boolean给... ...

错误行:while($ lvl = mysqli_fetch_array($ lvls))

$result = mysqli_query($conn, "SELECT count(*) FROM players");
$roww = mysqli_fetch_row($result);
$total = $roww[0];
$playersCount = mysqli_fetch_row($result);
$pagesCount = ceil($playersCount / $playersOnPage);
$fromLimit = ($currentPage - 1) * $playersOnPage;
$dbquery = "SELECT * FROM `players` ORDER BY `score` DESC".$fromLimit.",   ".$playersOnPage."";
$lvls = mysqli_query($conn, $dbquery, MYSQLI_USE_RESULT);

while($lvl = mysqli_fetch_array($lvls))

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码:

$result = mysqli_query($conn, "SELECT count(*) FROM players");
$roww = mysqli_fetch_row($result);
$total = $roww[0];
$playersCount = mysqli_fetch_row($result);
$pagesCount = ceil($playersCount / $playersOnPage);
$fromLimit = ($currentPage - 1) * $playersOnPage;

//Here was the mistake!
$dbquery = "SELECT * FROM `players` ORDER BY `score` DESC LIMIT ".$fromLimit.", ".$playersOnPage;
$lvls = mysqli_query($conn, $dbquery, MYSQLI_USE_RESULT);

while($lvl = mysqli_fetch_array($lvls))

<强>解释

$dbquery的结果如下所示:

SELECT * FROM `players` ORDER BY `score` DESC1,  2 -- not valid!

使用上述解决方案中的新$dbquery,您可以获得以下内容:

SELECT * FROM `players` ORDER BY `score` DESC LIMIT 1, 2 -- valid