0

I keep getting an error on line 20, "if(mysqli_num_rows != 0)". The error reads:

"Notice: Use of undefined constant mysqli_num_rows - assumed 'mysqli_num_rows' in C:\wamp\www\movieDB\movies.php on line 20"

It's probably just a stupid mistake that I'm overlooking, but I've tried just about everything I can figure. Thank you in advance!

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.";
            }
        }

    ?>

The HTML

<!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>
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
  • Besides [`mysqli_num_rows`](http://php.net/manual/en/mysqli-result.num-rows.php) not being called as a `function()`, you haven't [queried](http://php.net/manual/en/mysqli.query.php) yet, so you can't go any further. Pay $200 and don't PASS GO. – Funk Forty Niner Jan 19 '15 at 22:12
  • _'stupid mistake'_: it's `mysqli` not `MySQLi`; you never actually execute a query; your code to fetch data is encapsulated in a function that's never called, and `mysql_num_rows` should be `mysqli_num_rows()`. That should keep you busy for a while. There may be more. –  Jan 19 '15 at 22:13

2 Answers2

0

mysqli_num_rows requires a parameter which holds the results in order to work.

$resultSet is not calling anything. You need mysqli_query.

Try this:

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.";
        }
}
l33cher
  • 21
  • 5
0
<?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() is function, and it must contains at least one parametr http://php.net/manual/en/mysqli-result.num-rows.php

Dmitry G
  • 93
  • 1
  • 8