Error in function mysqli_num_rows()

Asked

Viewed 28 times

1

I want the results of an SQL query to be returned on the screen, with the following code:

<?php

include "header.php";

    $query = "SELECT (titulo_artigo, subtitulo_artigo, conteudo_artigo) FROM tb_artigo WHERE id_tb_artigo = 14";

    $conexao = mysqli_connect('127.0.0.1:3307', 'root', '', 'artigo') or die("erro conexao");

    $resultado = mysqli_query($conexao, $query);

    if (mysqli_num_rows($resultado) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "<h2>" . $row["titulo_artigo"]. "</h2><h3>". $row["subtitulo_artigo"]. "</h3><p>" . $row["conteudo_artigo"]. "</p><br>";
    }

    } else {
        echo "0 results";
    }

include "footer.php";

?>

However, when I try to run it, it returns the following error:

Warning: mysqli_num_rows() expects Parameter 1 to be mysqli_result, bool Given on line 11

  • If you read the documentation, you will see that mysqli_query returns false when your SQL fails, which was the case. In the link above there is more information about an equivalent error.

  • @Andersoncarloswoss, thank you very much worked here :D

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.