Warning: mysqli_fetch_object () expects parameter 1 to be mysqli_result, boolean given in /home/omeganim/public_html/index.php on line 39

0

I need help solving this error !!!

Warning: mysqli_fetch_object () expects parameter 1 to be mysqli_result, boolean given in /home/omeganim/public_html/index.php on line 39

The code is this:

 $pagCorrente = 1;
 if(isset($_GET['pag'])){
     $pagCorrente = (int)$_GET['pag'];
 }
 $mostrar = 10;


 $pagCorrente = $pagCorrente * $mostrar - $mostrar;



 $sql = "SELECT count(id) as total FROM listas";     
 $ex = $conexao->query($sql);    
 $total = mysqli_fetch_object($ex);  
 $total = $total->total;

 $quantPages = ceil($total / $mostrar);




 $sql = "SELECT * FROM listas ORDER BY id desc LIMIT $pagCorrente,$mostrar";
 $wx = $conexao->query($sql);





 while($linha = mysqli_fetch_object($wx)){


 ?>
 <div class="engloba1">
  <div>


    <a href="<?php echo SITE . 'nomes.php?id='.$linha->id; ?>">
    <img src='<?php echo SITE . 'php/upload/' . $linha->imagen;?>' />

    <div class='box'>
     <p>
      <br><?php echo $linha->titulo;?> </br>
      </a>
      <a href="<?php echo SITE . 'nomes.php?id='.$linha->id; ?>">
      <br><?php echo $linha->nome;?> </br>
      <br><?php echo $linha->epi;?> </br>
      </a>
     </p>
     </div>
     </div>
   </div>

   <?php } ?>

Thank you in advance !!

    
asked by anonymous 22.04.2017 / 02:11

1 answer

0

Usually this error happens when the query executed in the database has some error.

Soon after running $conexao->query print the last error that happened in the database with $conexao->error . Staying like this:

 /* ... ... */
 $sql = "SELECT count(id) as total FROM listas";     
 $ex = $conexao->query($sql);   

 echo $conexao->error;

 $total = mysqli_fetch_object($ex);  
 $total = $total->total;

 $quantPages = ceil($total / $mostrar);

 $sql = "SELECT * FROM listas ORDER BY id desc LIMIT $pagCorrente,$mostrar";
 $wx = $conexao->query($sql);

 echo $conexao->error;
 exit; //opcional, para poder visualizar melhor a saida de erro
 while($linha = mysqli_fetch_object($wx)){

 /* ... ... */

There is an error in your sql query (it may be a wrong column name written, etc.) you can not guess.

I have noticed an important detail. Is your variable $conexao an instance of the mysqli class? In other words, did you $conexao = new mysqli(...) ? The above method will only work if it has been done that way. In addition you can simply call fecth_object directly from the resultset. Something like this: $conexao->fetch_object();

    
22.04.2017 / 16:38