如何修复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))
答案 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