从数据库打印项目时遇到问题



我一直得到一个error on line 20, "if(mysqli_num_rows != 0)".错误如下:

"Notice: Use of undefined constant mysqli_num_rows - assumed 'mysqli_num_rows' in C:wampwwwmovieDBmovies.php on line 20"

这可能只是一个我忽略的愚蠢错误,但我已经尝试了我能想到的一切。提前谢谢你!

enter code here
<?php
$mysqli = NEW MySQLi('localhost', 'root', '', 'movies');    
$resultSet = ("SELECT * FROM movie");

     function query () 
    {
        if(mysqli_num_rows != 0) 
        {
            while ($rows = $resultSet->fetch_assoc()) 
            {
                $title = $rows['title'];
                $date = $rows['releaseDate'];
                $dFirst = $rows['directorFirst'];
                $dLast = $rows['directorLast'];
                    echo "<p>Name: $title, $date<br>Director: $dFirst $dLast";
                }
            }else 
            {
            echo "No results.";
            }
        }
    ?>

该目录

<!DOCTYPE html>
<html>
    <head>
        <title>Movies</title>
        <link rel="stylesheet" type="text/css" href="movies.css">
        <link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:300' rel='stylesheet' type='text/css'>
            <?php require("movies.php");?>
    </head>
    <body>
        <h1>Hello World!!!</h1>
        <a href="index.php">Home</a>
        <div class="movies">
            <div>
                <?php
                query();
                ?>
            </div>
        </div>
    </body>
</html>

>mysqli_num_rows需要一个参数来保存结果才能工作。

$resultSet没有打电话。你需要mysqli_query。

试试这个:

function query () 
{
    $mysqli = NEW MySQLi('localhost', 'root', '', 'movies');    
    $resultSet = mysqli_query($mysqli, "SELECT * FROM movie");
    if(mysqli_num_rows($resultSet) != 0) 
    {
        while ($rows = $resultSet->fetch_assoc($resultSet)) 
        {
            $title = $rows['title'];
            $date = $rows['releaseDate'];
            $dFirst = $rows['directorFirst'];
            $dLast = $rows['directorLast'];
                echo "<p>Name: $title, $date<br>Director: $dFirst $dLast";
            }
        }else 
        {
        echo "No results.";
        }
}
<?php
     function query () 
    {
        $mysqli = NEW MySQLi('localhost', 'root', '', 'movies');    
        $resultSet = ("SELECT * FROM movie");
        if(mysqli_num_rows($resultSet) != 0) 
        {
            while ($rows = $resultSet->fetch_assoc()) 
            {
                $title = $rows['title'];
                $date = $rows['releaseDate'];
                $dFirst = $rows['directorFirst'];
                $dLast = $rows['directorLast'];
                    echo "<p>Name: $title, $date<br>Director: $dFirst $dLast";
                }
            }else 
            {
            echo "No results.";
            }
        }
    ?>

mysqli_num_rows() 是函数,它必须至少包含一个参数http://php.net/manual/en/mysqli-result.num-rows.php

相关内容

  • 没有找到相关文章

最新更新