I can not make a select in a database using PHP

0

Hi everyone, I'm not able to do a select in my PHP database. I already tried to implement several solutions, however it always returns 0 results, and I have data in my DB.

I am using external files to connect to the bank and they are working.

And the contents of the spans always remain empty.

<?php $idUser = $_SESSION["user_id"];

  if (mysqli_num_rows($result) > 0) {
         $result =  mysqli_query("SELECT idMessage, name, telefone, mensagem FROM Messages where Messages.idUser =  '$idUser' ");
          while($row = mysql_fetch_array($result)) :
            $id  = $row["idMessage"];
            $name = $row["name"];
            $mensagem = $row["mensagem"];
          endwhile;
       } else {
            echo "0 results";
          }
  ?>

      <span><?php  echo $id ?></span>
      <span><?php  echo $name ?></span>
      <span><?php  echo $mensagem ?></span>
    
asked by anonymous 18.06.2018 / 03:36

1 answer

1

or $ result I believe it should be before if and not after. thus:

$result =  mysqli_query("SELECT idMessage, name, telefone, mensagem FROM Messages where Messages.idUser =  '$idUser' ");
if (mysqli_num_rows($result) > 0) {
         ...
         ...
    
18.06.2018 / 18:20