0

I have written an SQL search that works when I run it inside php-admin (version details below) but when I include it in a php script the search gives the following error:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\index.php on line 1356

I also tried creating a temporary table instead of creating and dropping a table but same error. I am stumped. I have various other similar searches within the same web page that run correctly. The only thing different between them and this search is the creation of another table.

I have searched for an obvious solution as to why this does not work but cannot find one anywhere. Thanks for any help.

$conn    = mysqli_connect("localhost", "root", "", "bgdatabase");

$sqlget  = "
CREATE OR REPLACE TABLE winners
SELECT round, MAX(score) AS maxscore
FROM gamedetail
GROUP BY round
ORDER BY round
ASC;

SELECT players.playerName, COUNT(gamedetail.playerID)
FROM gamedetail
JOIN winners
ON gamedetail.round = winners.round
JOIN players
ON players.playerID = gamedetail.playerID
AND gamedetail.score = winners.maxscore
WHERE winners.maxscore <> 0
GROUP BY players.playerID
ORDER BY COUNT(gamedetail.playerID)
DESC
LIMIT 10;

DROP TABLE winners
";

$sqldata = mysqli_query($conn, $sqlget);  


        echo " <div class='four columns'>";


            echo "<table>";
            echo "<tr><th>Name</th><th>Wins</th></tr>";

            while($row = mysqli_fetch_array($sqldata, MYSQLI_ASSOC)) {
              echo "<tr><td>";
              echo $row['players.playerName'];
              echo "</td><td>";
              echo $row['COUNT(gamedetail.playerID)'];
              echo "</td></tr>";

            }
            echo "</table>";

        echo "</div>";

Database server

Server: 127.0.0.1 via TCP/IP Server type: MariaDB Server connection: SSL is not being used Documentation Server version: 10.3.16-MariaDB - mariadb.org binary distribution Protocol version: 10 User: root@localhost Server charset: cp1252 West European (latin1)

Web server

Apache/2.4.39 (Win64) OpenSSL/1.1.1c PHP/7.3.7 Database client version: libmysql - mysqlnd 5.0.12-dev - 20150407 - $Id: 7cc7cc96e675f6d72e5cf0f267f48e167c2abb23 $ PHP extension: mysqliDocumentation curlDocumentation mbstringDocumentation PHP version: 7.3.7

phpMyAdmin

Version information: 4.9.0.1, latest stable version: 4.9.5

0 Answers0