PHP错误 - SQL结果无效

时间:2013-09-21 20:23:14

标签: php sql

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

错误:

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


的index.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>

2 个答案:

答案 0 :(得分:2)

您正在混合mysqli_*mysql_*个功能;这是行不通的。

答案 1 :(得分:1)

如前所述,混合mysqli_*mysql_*功能将无效。

此外,mysql_num_rows期望资源作为参数而不是SQL查询字符串。正如PHP manual

中所述