PHP 错误 - 无效的 SQL 结果


PHP ERROR - Invalid SQL result

我在创建的模拟站点上收到此错误。不确定这里的实际问题是什么。任何帮助将不胜感激。谢谢!

错误:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home4/user/public_html/index.php on line 6

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home4/user/public_html/index.php on line 8


索引.php

<?php
    include_once("php_includes/check_login_status.php");
    $sql = "SELECT username FROM users WHERE activated = '1' ";
    $query = mysqli_query($db_conx, $sql );
    $usernumrows = mysql_num_rows($query);
    $userlist = "";
    while($row = mysql_fetch_array($query, MYSQLI_ASSOC)) {
        $u = $row["username"];
        $userlist .='<a href = "user.php?u='.$u.'">'.$u.'</a> &nbsp; | &nbsp;';
    }
?>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>RM</title>
        <link rel="stylesheet" href="style/style.css">
        <script src="js/main.js"></script>
    </head>
    <body>
        <?php include_once("template_pageTop.php"); ?>
        <div id="pageMiddle">&nbsp;</div>
        <?php include_once("template_pageBottom.php"); ?>
    </body>
</html>

你混合了mysqli_*mysql_*函数;这是行不通的。

如前所述,混合mysqli_*mysql_*函数是行不通的。

此外,mysql_num_rows期望资源作为参数而不是 SQL 查询字符串。如PHP手册中所述